Saturday, 19 January 2013

Reverse a Linked List(Program)


By on 07:53

Now I create/print a program that reverse the whole linked list.I made this program in c ++ but you can also creates it with java and c# also,with same concept which are given below.


#include<iostream.h>
#include<conio.h>
#include null 0
#include<stdio.h>
#include<stdlib.h>
struct link
{
int info;
struct link* next;
}*start,*node;
void rev(struct link*);
void create(struct link*);
void main()
{
create(start);
rev(start);
getch();
}
void create(struct link*node)
{
char ch;
clrscr();
start=null;
node=null;
do
{
if(node==null)
{
node=new link;
start=node;
}
else
{
node->next=node link;
node=node->next;
}
cout<<"enter information for node";
cin>>node->info;
Cout<<"want to continue";
flushall();
cin>>ch;
}while(ch!='n');
node->next=null;
}
void rev(struct link*node)
{
if node()
{
rev(node->next);//recursion 
cout<<node->info;
}
getch();
}



That's all about Reverse of the Linked List in data structure.


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...