I wrote code for linked list and drawn diagram for list to show behavior. I just want to verify that description shown in picture match with code. Does it really match ?
Code:
#include<stdio.h>#include<stdlib.h>
struct Node
{
int Marks;
struct Node *next;
};
struct Node* newStudent(int n, struct Node *Ps) {
struct Node *new = malloc(sizeof(*new));
printf(" Location new : %p \n", (void*)new);
new->Marks = n ;
new->next = Ps;
return new;
}
void Display(struct Node *Ps){
struct Node *c;
c = Ps;
while (c!=NULL){
printf(" %d\n",c->Marks);
c = c->next;
}
}
int main (void )
{
struct Node *Ps = NULL;
printf(" Location Ps : %p \n", (void*)Ps);
Ps = newStudent(75, Ps);
printf(" Location Ps : %p \n", (void*)Ps);
Ps = newStudent(85, Ps);
printf(" Location Ps : %p \n", (void*)Ps);
Ps = newStudent(72, Ps);
printf(" Location Ps : %p \n", (void*)Ps);
Ps = newStudent(68, Ps);
printf(" Location Ps : %p \n", (void*)Ps);
Display(Ps);
return 0;
}
Result
Code:
Location Ps : 00000000 Location new : 00641448
Location Ps : 00641448
Location new : 00641478
Location Ps : 00641478
Location new : 00641488
Location Ps : 00641488
Location new : 00641498
Location Ps : 00641498
68
72
85
75