.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> OOPS >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

TRAVERSAL IN A LIST

Posted By:Nikhil Kumar       Posted Date: February 28, 2010    Points: 10    Category: OOPS    URL: http://www.dotnetspark.com  

TRAVERSAL IN A LIST IN C PROGRAMMING...
 

 

////TRAVERSAL IN A LIST////
 
#include
#include
#include
#include
struct node {         
                                              int info;
                                              node*next;
                                              
                                              }*start,*newptr,*save,*ptr,*rear;
 
node *newnode(int) ;           
                      //to create nmew node
void insert(node*) ;
void travers(node*);
void main()
{
clrscr();
start=rear=NULL;
int inf;
char ch='y';
while(ch=='y')
{
cout<<"ENTER INFo IN NEW NODE:";
cin>>inf;
newptr=newnode(inf);
insert(newptr);
cout<<"PRESS Y TO ENTER NEW NODE:";
cin>>ch;
}
do{cout<<"THE LIST NOW IS:";
traverse(start);
getch();
}
while(ch=='y');
}
node*newnode(int n)
{
ptr=new node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void insert(node*np)
{
if (start==NULL)start=rear=np;
else {
 
rear->next=np;
rear=np;
}
}
void traverse(node*np)
{
while (np!=NULL)
{
cout<info<<"->";
np=np->next;
}
cout<<"!!!\n";
}
 
 
OUTPUT
 
ENTER INFO IN NEW NODE:2
PRESS Y TO ENTER NEW NODE:y
ENTER INFO IN NEW NODE:34
PRESS Y TO ENTER NEW NODE:y
ENTER INFO IN NEW NODE:54
PRESS Y TO ENTER NEW NODE:n
THE LIST NOW IS:1->2->34->54->!!!


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend