What steps would i take to complete insertStudents and deleteStudents functions?
I know i have to add a dummy node. Any hints at a direction would be helpful.
Code:
/*
Complete insertStudents and deleteStudents functions in the skeleton program.
The output of the program should be like:
sid=001,name=John
sid=002,name=Joan
sid=003,name=Jack
sid=001,name=John
sid=003,name=Jack
*/
#include "ex6.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
Snodeptr students;
//Create the dummy node
makenullStudents(&students);
struct studentType student1,student2,student3;
strcpy(student1.sid,"001");
strcpy(student1.sname,"John");
strcpy(student2.sid,"002");
strcpy(student2.sname,"Joan");
strcpy(student3.sid,"003");
strcpy(student3.sname,"Jack");
insertStudents(student1,students);
insertStudents(student2,students);
insertStudents(student3,students);
printStudents(students);
deleteStudents(student2,students);
printStudents(students);
return 0;
}
Snodeptr sAlloc(void) {
return (Snodeptr) malloc(sizeof(struct snode));
}
void makenullStudents(Snodeptr *students) {
(*students)=sAlloc();
}
void insertStudents(struct studentType x, Snodeptr students) {
}
void deleteStudents(struct studentType x, Snodeptr students) {
}
void printStudents(Snodeptr students) {
int count=0;
Snodeptr p=students;
char ch;
while((p->next)!=NULL){
printf("sid=%s,name=%s\n",p->next->student.sid,p->next->student.sname);
p=p->next;
}
}