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 inf...
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.
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.
COMMENTS