Showing posts with label Linked List. Show all posts
Showing posts with label Linked List. Show all posts

Saturday, 19 January 2013

Reverse a Linked List(Program)


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.

Doubly Linked List


After explaining singly linked list,circular linked list so now I explain you a doubly linked list.In singly linked list,each node has two parts i.e. info part/operation part and next pointer but in doubly linked list each node has 3 parts i.e. info,next pointer and pre part(so this is the main advantage of doubly linked list as compared to singly linked list).It is used in c ++,java,c# etc.

Example/implementation or Algorithm/program of Doubly linked  list:-



#include<iostream.h>

#include<conio.h>
#include null 0
#include<stdio.h>
#include<stdlib.h>

void main()

{
struct link
{
int info;
struct link* next*pre;
}*start,*node*last;
char ch;
clrscr();
start=null;
node=null;
do
{
if(node==null)
{
node=new link;
start=node;
node->pre=null;
}
else
{
node->next=node link;
node->next->pre=null;
node=node->next;
}
cout<<"enter information for node";
cin>>node->info;
Cout<<"want to continue";
flushall();
cin>>ch;
}while(ch!='n');
last=node;
node->next=null;
node=start;
cout<<"List=";
while(node)
{
cout<<node->info;
node=node->next;
}
node=last;
cout<<"Reverse list/reversing a list";
while (node)
{
cout<<node->info;
node=node->pre;

getch();
}




That's all about Doubly 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.

Circular Linked List


Circular linked list  are those linked list which are reaching the first node after reaching the end node.In circular linked list the last  node not contains the NULL pointer but contain the address of first node.It is used in c ++,java,c# etc.



Example/implementation or Algorithm/program of Circular linked  list:-



#include<iostream.h>

#include<conio.h>
#include null 0
#include<stdio.h>
#include<stdlib.h>

void main()

{
struct link
{
int info;
struct link* next;
}*start,*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;
node=start;
cout<<"List=";
do
{
cout<<node->info;
node=node->next;
}while(node!=start);
getch();
}



That's all about Circular 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.

Singly Linked List


A linked list is a collection of node which are interlinked to each other.In singly linked list(Single list) each node has 2 parts i.e info part/operation part as well as next pointer.It is used in c ++,java,c# etc.


Simple example/implementation of Singly linked  list:-




Q)Write a program to made singly linked list and display it?



#include<iostream.h>
#include<conio.h>
#include null 0
#include<stdio.h>
#include<stdlib.h>

void main()

{
struct link
{
int info;
struct link* next;
}*start,*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;
node=start;
cout<<"List=";
while node()
{
cout<<node->info;
node=node->next;
}
getch();
}



That's all about Singly 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.

Friday, 18 January 2013

Linked List


Linked List is a collection of node which are interlinked to each other.Each node contains 2 part namely information part/operation part(contains integer,character,string etc) and next pointer(contain the address of node).




Advantage and Disadvantage of Linked List:-


1)Dynamic Memory Location and used in c ++,java,c# etc.

2)Quick deletion.
3)Quick Insertion.
4)Searching is very slow(dis).

Type of Linked List:-


1)Singly Linked List

2)Circular Linked list
3)Doubly Linked List
4)Doubly Circular Linked List

Simple example/implementation of linked list:-


Q)Write a program to made linked list and print sum and average?


#include<iostream.h>

#include<conio.h>
#include null 0
#include<stdio.h>
#include<stdlib.h>

void main()

{
struct link
{
int info;
struct link* next;
}*start,*node;
char ch;
int s,avg,c;
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;
s=c=0;
node=start;
cout<<"List=";
while node()
{
s=s+node->info;
c++;
node=node->next;
}
avg=s/c;
cout<<s<<avg;
getch();
}



That's all about 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.