Im having some difficulty with linked list, im giving this code #define MAXNUM 1
ID: 3657001 • Letter: I
Question
Im having some difficulty with linked list,
im giving this code
#define MAXNUM 10
#define MAXNAME 30
typedef struct enode *Enodeptr;
typedef struct snode *Snodeptr;
typedef struct cnode *Cnodeptr;
struct studentType {
char sid[MAXNUM];
char sname[MAXNAME];
};
struct courseType {
char cno[MAXNUM];
char title[MAXNAME];
int hours;
};
struct snode {
struct studentType student;
Enodeptr firstE;
Snodeptr next,prior;
};
struct cnode {
struct courseType course;
Enodeptr firstE;
Cnodeptr next,prior;
};
struct enode {
Enodeptr sNext, cNext;
Snodeptr sOwner;
Cnodeptr cOwner;
char grade;
};
//and what we have to do is create a student.c file that does this
Snodeptr sAlloc(void);
/* Allocates storage for a snode and returns pointer to the structure */
void makenullStudents(Snodeptr *students);
/* Creates an empty list of students and returns pointer to dummy node
in the variable students */
int insertStudents(struct studentType x, Snodeptr students);
/* inserts the student structure x in the student list; returns 0
if successful and 1 if failed */
int deleteStudents(struct studentType x, Snodeptr students, Cnodeptr courses);
/* deletes the student structure x in the student list; returns 0
if successful and 1 if failed */
int memberStudents(struct studentType x, Snodeptr students, Snodeptr *s);
/* returns 0 if student structure x is present in students list
and 1 otherwise. It also returns a pointer (in s) to the snode where it
found x; If x is not found it should return a pointer to the snode
where x should be inserted */
void printStudents(Snodeptr students);
/* prints the list of students (sid and names) in pretty format with
-more- like option */
/***********************************8
what i have come up with is
*******************************
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "types.h"
#include "students.h"
#include "enrolls.h"
Snodeptr sAlloc(void) {
return (Snodeptr) malloc(sizeof(struct snode));
}
void makenullStudents(Snodeptr *students) {
(*students)=sAlloc();
}
int memberStudents(struct studentType x, Snodeptr students, Snodeptr *s) {
return 0;
}
int insertStudents(struct studentType x, Snodeptr students) {
Snodeptr p=students;
while(p->next!=NULL)
"students.c" 65L, 1082C 17,1 Top
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "types.h"
#include "students.h"
#include "enrolls.h"
Snodeptr sAlloc(void) {
return (Snodeptr) malloc(sizeof(struct snode));
}
void makenullStudents(Snodeptr *students) {
(*students)=sAlloc();
}
int memberStudents(struct studentType x, Snodeptr students, Snodeptr *s) {
Snodeptr p=students;
Snodeptr p1=*s;
while(strcmp(p->next->student.sid, x.sid))
{
p=p->next;
}
return 0;
}
int insertStudents(struct studentType x, Snodeptr students) {
Snodeptr p=students;
while(p->next!=NULL)
{
p=p->next;
}
Snodeptr new=malloc(sizeof (struct snode));
new->student=x;
p->next=new;
new->prior=p;
new->next=NULL;
return 0;
}
int deleteStudents(struct studentType x, Snodeptr students, Cnodeptr courses) {
Snodeptr p=students;
Snodeptr p1;
while(!strcmp(p->next->student.sid, x.sid))
{
p=p->next;
}
p1=p->next;
p->next=p->next->next;
p->next->prior=p;
return 0;
}
void printStudents(Snodeptr students) {
int count=0;
Snodeptr p=students;
char ch;
while((p->next)!=NULL)
{
printf("sid=%s, name=%s",p->next->student.sid,p->next->student.sname);
p=p->next;
}
}
****************************************888
Im not really good with linked list and want some guideance on my code especially the memeber students