EmbLogic's Blog

linked list prog and output

this is the program for connecting 7nodes……

#include
int main(void)
{

struct node
{
int info;
struct node *d;
};
struct node d1,*n,*t;

{ int i;
d1.d=(struct node*) malloc(sizeof(struct node));
printf(“\nmemory allocation for pointer p of d1\n”);

printf(“\nd1.d=%d\n”,d1.d);
n=(struct node*)malloc(sizeof(struct node));
printf(“\ngiving base address to pointer n\n”);

printf(“\n*n=%d\n”,n);
d1.d=n;
printf(“\n2nd node created.pointer d is having base address of pointer n\n”);

printf(“\nd1.d=%d”,d1.d);

t=n;
printf(“\nlinking 2nd 3rd node t=n\n”);

printf(“\n*t=%d\n”,*t);
for(i=0;id=n;
printf(“\nlinking node %d %d =%d\n”,i+3,i+4,t->d);
t=(struct node*)malloc(sizeof(struct node));
printf(“\n getting anothrer base adderess =%d\n”,*t);

n->d=t;
printf(“\nlinking node %d %d =%d\n”,i+4,i+5,n->d);

} return 0;

————————————————————————————————————————————————

output for linked list……………………….

memory allocation for pointer p of d1

d1.d=149512200

giving base address to pointer n

*n=149512216

2nd node created.pointer d is having base address of pointer n

d1.d=149512216
linking 2nd 3rd node t=n

*t=0

the loop has started from here

n has got the base adderess=0

linking node 3 4 =149512232

getting anothrer base adderess =0

linking node 4 5 =149512248

the loop has started from here

n has got the base adderess=0

linking node 4 5 =149512264

getting anothrer base adderess =0

linking node 5 6 =149512280
………………………………………………………………………………….

sir as i have taken 2 pointers..n equate them in 2/3rd step so that pointers should have same addresses bt after equating them gettin *t=0…..

kindly tell me the areas at which im getting short…..
thank you

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>