Linked List is a collection of node which are interlinked to each other.Each node contains 2 part namely information part/operation part(co...
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.
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.
COMMENTS