Trouble with linked list implementation of queue.

Why doesn't this program run? I suspect something is wrong with the underlined part.

#include<iostream.h>
#include<conio.h>
struct node{char c;
node* nxt;};
void disp(node *fresh) {cout<<"\n";
char o=fresh->c;
while (o!='\0') {cout<<o;
fresh=fresh->nxt;
o=fresh->c;
}
cout<<"\n";}
void main(){
clrscr();
node *s,*t,*u,*v;
s=new node;s->c='p';s->nxt=t; t=new node;t->c='i';t->nxt=u; u=new node;u->c='g';u->nxt=v; v=new node;v->c='\0';v->nxt=NULL;
disp (s);
getch();}
Last edited on
Wowthatcodeishard
tolookat. Codeformattingis
important. Youaretryingtocommunicateto
otherswhatyouralgorithmdoes.
1
2
s->nxt=t; 
t=new node; //t change its value, so s->nxt = garbage 

You shouldn't be doing that manually. Create a list class, and a queue class.
Thanks a lot ne555. I got it.
Topic archived. No new replies allowed.