English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

1 and the lastnode contains 2048) and pointer P that refers to the last node...what does this code do?
while(p->next!=p){
p->next=p->next=->next;
p=p->next;
}
cout<< p->info;

2007-03-22 06:26:58 · 2 answers · asked by hihi b 1 in Computers & Internet Programming & Design

2 answers

if it was h->next wher h is a pointer to the node,instead of p(which is a pointer already pointin to the last node),n if we omit the 2nd line,then the code checks for the end of the linked list.Otherwise the code is wrong.it shld rather be...

while(h->next!=p){
h=h->next;
}
cout<< h->info;

but doin all this jus to print the info of the last node does not make any sense coz it cld be directy printed using p->info since p is alraedy pointin to the last node.


this makes only sense if u want to read the info of every node till u reach the end.(assumin h strts frm the strt node)


ps-if the above code is perfect then i think the code jus gets trapped into an infinite loop.ignoring the 2nd(p->next=p->next=->next;)of course...

2007-03-22 08:07:26 · answer #1 · answered by freeze 2 · 0 0

it is just a piece of Scheme code, that gives the program instructions to do a command for more info if needed.

2007-03-22 06:36:12 · answer #2 · answered by Nic 3 · 0 0

fedest.com, questions and answers