International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 1
-Varsha Degaonkar
www.isquareit.edu.in
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
2
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 3
INTRODUCTION
SINGLY LINKED LIST (SLL):
• Singly Linked List is collection of data elements.
• Each element represents a node in SLL.
• Each node consists of
one or more data fields and
one address field which stores the address of next node.
• Operations in SLL:
Creation
Insertion
Display
SINGLY LINKED LIST
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct sll
{ int data;
struct sll *next;
}sll;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 4
Structure
definition
Creation of user
defined data
type.
SINGLY LINKED LIST
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct sll
{ int data;
struct sll *next;
}sll;
void main()
{
int op;
sll *head=NULL;
clrscr();
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 5
Pointer variable declaration of the
Structure and assigning value to it
data *next
Node of SLL:
sll *create(sll *); /*function declaration*/
sll *insert(sll *); /*function declaration*/
void disp(sll *); /*function declaration*/
do // menu driven program
{
printf("1)Createn2)Insertn3) Displayn4)Exit");
printf("nEnter the option: ");
scanf("%d",&op);
switch(op)
{
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 6
case 1:
head=create(head);
/*Function Call*/
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 7
sll *create(sll *head)
{
sll *p,*nw;
char ans;
do
{
nw=(sll*)malloc(sizeof(sll));nw=500
case 1:
head=create(head);
/*Function Call*/
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 8
sll *create(sll *head)
{
sll *p,*nw;
char ans;
do
{
nw=(sll*)malloc(sizeof(sll));
nw->next=NULL;
NULL
nw=500
case 1:
head=create(head);
/*Function Call*/
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 9
sll *create(sll *head)
{
sll *p,*nw;
char ans;
do
{
nw=(sll*)malloc(sizeof(sll));
nw->next=NULL;
printf("nEnter the data:");
scanf("%d",&(nw->data));
NULL10
nw=500
case 1:
head=create(head);
/*Function Call*/
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 10
sll *create(sll *head)
{
sll *p,*nw;
char ans;
do
{
nw=(sll*)malloc(sizeof(sll));
nw->next=NULL;
printf("nEnter the data:");
scanf("%d",&(nw->data));
if(head==NULL)
NULL10
nw=500
case 1:
head=create(head);
/*Function Call*/
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email -
info@isquareit.edu.in 11
sll *create(sll *head)
{
sll *p,*nw;
char ans;
do
{
nw=(sll*)malloc(sizeof(sll));
nw->next=NULL;
printf("nEnter the data:");
scanf("%d",&(nw->data));
if(head==NULL)
p=head=nw;
NULL10
p=head=nw=500
case 1:
head=create(head);
/*Function Call*/
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
12
sll *create(sll *head)
{
sll *p,*nw;
char ans;
do
{
nw=(sll*)malloc(sizeof(sll));
nw->next=NULL;
printf("nEnter the data:");
scanf("%d",&(nw->data));
if(head==NULL)
p=head=nw;
else
NULL10
p =head=500
NULL20
nw=600
case 1:
head=create(head);
/*Function Call*/
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
13
sll *create(sll *head)
{
sll *p,*nw;
char ans;
do
{
nw=(sll*)malloc(sizeof(sll));
nw->next=NULL;
printf("nEnter the data:");
scanf("%d",&(nw->data));
if(head==NULL)
p=head=nw;
else
{
p->next=nw;
60010
p=head=500
NULL20
nw=600
case 1:
head=create(head);
/*Function Call*/
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 14
sll *create(sll *head)
{
sll *p,*nw;
char ans;
do
{
nw=(sll*)malloc(sizeof(sll));
nw->next=NULL;
printf("nEnter the data:");
scanf("%d",&(nw->data));
if(head==NULL)
p=head=nw;
else
{
p->next=nw;
p=nw;
}
60010
p=head=500
NULL20
p=nw=600
case 1:
head=create(head);
/*Function Call*/
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 15
sll *create(sll *head)
{
sll *p,*nw;
char ans;
do
{ nw=(sll*)malloc(sizeof(sll));
nw->next=NULL;
printf("nEnter the data:");
scanf("%d",&(nw->data));
if(head==NULL)
p=head=nw;
else
{ p->next=nw;
p=nw;
}
printf("nt Do you want to insert node(Y/N)"); flushall();
scanf("%c",&ans);
}while(ans=='y'||ans=='Y');
return(head);
}
60010
head=500
NULL20
p=600
NULL30
nw=700
case 1:
head=create(head);
/*Function Call*/
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 16
sll *create(sll *head)
{
sll *p,*nw;
char ans;
do
{ nw=(sll*)malloc(sizeof(sll));
nw->next=NULL;
printf("nEnter the data:");
scanf("%d",&(nw->data));
if(head==NULL)
p=head=nw;
else
{ p->next=nw;
p=nw;
}
printf("nt Do you want to insert node(Y/N)"); flushall();
scanf("%c",&ans);
}while(ans=='y'||ans=='Y');
return(head);
}
60010
head=500
70020
p=600
NULL30
nw=700
case 1:
head=create(head);
/*Function Call*/
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 17
sll *create(sll *head)
{
sll *p,*nw;
char ans;
do
{ nw=(sll*)malloc(sizeof(sll));
nw->next=NULL;
printf("nEnter the data:");
scanf("%d",&(nw->data));
if(head==NULL)
p=head=nw;
else
{ p->next=nw;
p=nw;
}
printf("nt Do you want to insert node(Y/N)"); flushall();
scanf("%c",&ans);
}while(ans=='y'||ans=='Y');
return(head);
}
60010
head=500
70020
p=600
NULL30
p=nw=700
case 2:
head= insert(head);
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 18
sll *insert(sll *head)
{ sll *p,*q;
int loc,i;
printf("nEnter the location:");
scanf("%d",&loc); //enter location for node insertion
p=(sll*)malloc(sizeof(sll)); //create new node
printf("nenter a data:"); //enter data in node
scanf("%d",&(p->data));
if(loc==1) //Insertion as head node i.e. if position is 1
{
p->next=head;
head=p;
return(head);
}
60010
head=500
70020
600
NULL30
700
case 2:
head= insert(head);
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 19
sll *insert(sll *head)
{ sll *p,*q;
int loc,i;
printf("nEnter the location:");
scanf("%d",&loc); //enter location for node insertion
p=(sll*)malloc(sizeof(sll)); //create new node
printf("nenter a data:"); //enter data in node
scanf("%d",&(p->data));
if(loc==1) //Insertion as head node i.e. if position is 1
{
p->next=head;
head=p;
return(head);
}
60010
head=500
70020
600
NULL30
700
5
P=400
case 2:
head= insert(head);
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 20
sll *insert(sll *head)
{ sll *p,*q;
int loc,i;
printf("nEnter the location:");
scanf("%d",&loc); //enter location for node insertion
p=(sll*)malloc(sizeof(sll)); //create new node
printf("nenter a data:"); //enter data in node
scanf("%d",&(p->data));
if(loc==1) //Insertion as head node i.e. if position is 1
{
p->next=head;
head=p;
return(head);
}
60010
head=500
70020
600
NULL30
700
5005
p=head=400
case 2:
head= insert(head);
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
21
else // if insertion is at other position than head node
{
i=1;q=head;
while(i<loc-1)
{
q=q->next;
i++;
}
p->next=q->next;
q->next=p;
}
disp(head);
return(head);
}
60010
q=head=500
70020
600
NULL30
700
NULL25
p=750
case 2:
head= insert(head);
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 22
else // if insertion is at other position than head node
{
i=1;q=head;
while(i<loc-1)
{
q=q->next;
i++;
}
p->next=q->next;
q->next=p;
}
disp(head);
return(head);
}
60010
q=head=500
70020
q=600
NULL30
700
NULL25
p=750
case 2:
head= insert(head);
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 23
else // if insertion is at other position than head node
{
i=1;q=head;
while(i<loc-1)
{
q=q->next;
i++;
}
p->next=q->next;
q->next=p;
}
disp(head);
return(head);
}
60010
q=head=500
70020
q=600
NULL30
700
70025
p=750
case 2:
head= insert(head);
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 24
else // if insertion is at other position than head node
{
i=1;q=head;
while(i<loc-1)
{
q=q->next;
i++;
}
p->next=q->next;
q->next=p;
}
disp(head);
return(head);
}
60010
q=head=500
75020
q=600
NULL30
700
70025
p=750
case 3:
head= disp(head);
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
25
void disp(sll *head)
{
sll *p;
if(head==NULL)//if linked list is not created
printf("nEmpty Linked List");
else
{
printf("nn Created SLL:nn ");
for(p=head;p!=NULL;p=p->next)
printf("%d->",p->data);
printf("NULL");
}
}
60010
head=500
70020
600
NULL30
700
case 3:
head= disp(head);
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 26
void disp(sll *head)
{
sll *p;
if(head==NULL)//if linked list is not created
printf("nEmpty Linked List");
else
{
printf("nn Created SLL:nn ");
for(p=head;p!=NULL;p=p->next)
printf("%d->",p->data);
printf("NULL");
}
}
60010
p=head=500
70020
600
10->
NULL30
700
case 3:
head= disp(head);
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 27
60010
p=head=500
70020
p=600
10->20->
NULL30
700
void disp(sll *head)
{
sll *p;
if(head==NULL)//if linked list is not created
printf("nEmpty Linked List");
else
{
printf("nn Created SLL:nn ");
for(p=head;p!=NULL;p=p->next)
printf("%d->",p->data);
printf("NULL");
}
}
case 3:
head= disp(head);
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 28
60010
p=head=500
70020
p=600
10->20->30->
NULL30
p=700
void disp(sll *head)
{
sll *p;
if(head==NULL)//if linked list is not created
printf("nEmpty Linked List");
else
{
printf("nn Created SLL:nn ");
for(p=head;p!=NULL;p=p->next)
printf("%d->",p->data);
printf("NULL");
}
}
case 3:
head= disp(head);
break;
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 29
60010
p=head=500
70020
p=600
10->20->30-> NULL
NULL30
p=700 p=NULL
void disp(sll *head)
{
sll *p;
if(head==NULL)//if linked list is not created
printf("nEmpty Linked List");
else
{
printf("nn Created SLL:nn ");
for(p=head;p!=NULL;p=p->next)
printf("%d->",p->data);
printf("NULL");
}
}
}//end of switch-case
}while(op!=6); //end of Do-while loop
getch();
}//end of main function
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 30
International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 31
ABOUT US
International Institute of Information Technology (I²IT)
P-14, Rajiv Gandhi Infotech Park, Phase – 1, Hinjawadi, Pune – 411057, India
International Institute of Information Technology (I²IT) was established by Late Shri. P. P. Chhabria,
Founder Chairman of Finolex Group of Industries, a well-known philanthropist and former
President of Mahratta Chamber of Commerce, Industries and Agriculture (MCCIA).
I²IT aspires to be an academic leader recognized for innovation, quality teaching and research,
holding high moral values and a forward thinking institution that explores creative approaches
for the future.
 Phone: +91 20 2293 3441 / 2 / 3
Toll Free Line:1800-233-4499
Fax: +91 20 2293 4191
 Email: info@isquareit.edu.in
 Web: www.isquareit.edu.in
32

Singly Linked List & Data Structure

  • 1.
    International Institute ofInformation Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 1 -Varsha Degaonkar www.isquareit.edu.in
  • 2.
    International Institute ofInformation Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 2
  • 3.
    International Institute ofInformation Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 3 INTRODUCTION SINGLY LINKED LIST (SLL): • Singly Linked List is collection of data elements. • Each element represents a node in SLL. • Each node consists of one or more data fields and one address field which stores the address of next node. • Operations in SLL: Creation Insertion Display
  • 4.
    SINGLY LINKED LIST #include<stdio.h> #include<conio.h> #include<stdlib.h> typedefstruct sll { int data; struct sll *next; }sll; International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 4 Structure definition Creation of user defined data type.
  • 5.
    SINGLY LINKED LIST #include<stdio.h> #include<conio.h> #include<stdlib.h> typedefstruct sll { int data; struct sll *next; }sll; void main() { int op; sll *head=NULL; clrscr(); International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 5 Pointer variable declaration of the Structure and assigning value to it data *next Node of SLL:
  • 6.
    sll *create(sll *);/*function declaration*/ sll *insert(sll *); /*function declaration*/ void disp(sll *); /*function declaration*/ do // menu driven program { printf("1)Createn2)Insertn3) Displayn4)Exit"); printf("nEnter the option: "); scanf("%d",&op); switch(op) { International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 6
  • 7.
    case 1: head=create(head); /*Function Call*/ break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 7 sll *create(sll *head) { sll *p,*nw; char ans; do { nw=(sll*)malloc(sizeof(sll));nw=500
  • 8.
    case 1: head=create(head); /*Function Call*/ break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 8 sll *create(sll *head) { sll *p,*nw; char ans; do { nw=(sll*)malloc(sizeof(sll)); nw->next=NULL; NULL nw=500
  • 9.
    case 1: head=create(head); /*Function Call*/ break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 9 sll *create(sll *head) { sll *p,*nw; char ans; do { nw=(sll*)malloc(sizeof(sll)); nw->next=NULL; printf("nEnter the data:"); scanf("%d",&(nw->data)); NULL10 nw=500
  • 10.
    case 1: head=create(head); /*Function Call*/ break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 10 sll *create(sll *head) { sll *p,*nw; char ans; do { nw=(sll*)malloc(sizeof(sll)); nw->next=NULL; printf("nEnter the data:"); scanf("%d",&(nw->data)); if(head==NULL) NULL10 nw=500
  • 11.
    case 1: head=create(head); /*Function Call*/ break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 11 sll *create(sll *head) { sll *p,*nw; char ans; do { nw=(sll*)malloc(sizeof(sll)); nw->next=NULL; printf("nEnter the data:"); scanf("%d",&(nw->data)); if(head==NULL) p=head=nw; NULL10 p=head=nw=500
  • 12.
    case 1: head=create(head); /*Function Call*/ break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 12 sll *create(sll *head) { sll *p,*nw; char ans; do { nw=(sll*)malloc(sizeof(sll)); nw->next=NULL; printf("nEnter the data:"); scanf("%d",&(nw->data)); if(head==NULL) p=head=nw; else NULL10 p =head=500 NULL20 nw=600
  • 13.
    case 1: head=create(head); /*Function Call*/ break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 13 sll *create(sll *head) { sll *p,*nw; char ans; do { nw=(sll*)malloc(sizeof(sll)); nw->next=NULL; printf("nEnter the data:"); scanf("%d",&(nw->data)); if(head==NULL) p=head=nw; else { p->next=nw; 60010 p=head=500 NULL20 nw=600
  • 14.
    case 1: head=create(head); /*Function Call*/ break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 14 sll *create(sll *head) { sll *p,*nw; char ans; do { nw=(sll*)malloc(sizeof(sll)); nw->next=NULL; printf("nEnter the data:"); scanf("%d",&(nw->data)); if(head==NULL) p=head=nw; else { p->next=nw; p=nw; } 60010 p=head=500 NULL20 p=nw=600
  • 15.
    case 1: head=create(head); /*Function Call*/ break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 15 sll *create(sll *head) { sll *p,*nw; char ans; do { nw=(sll*)malloc(sizeof(sll)); nw->next=NULL; printf("nEnter the data:"); scanf("%d",&(nw->data)); if(head==NULL) p=head=nw; else { p->next=nw; p=nw; } printf("nt Do you want to insert node(Y/N)"); flushall(); scanf("%c",&ans); }while(ans=='y'||ans=='Y'); return(head); } 60010 head=500 NULL20 p=600 NULL30 nw=700
  • 16.
    case 1: head=create(head); /*Function Call*/ break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 16 sll *create(sll *head) { sll *p,*nw; char ans; do { nw=(sll*)malloc(sizeof(sll)); nw->next=NULL; printf("nEnter the data:"); scanf("%d",&(nw->data)); if(head==NULL) p=head=nw; else { p->next=nw; p=nw; } printf("nt Do you want to insert node(Y/N)"); flushall(); scanf("%c",&ans); }while(ans=='y'||ans=='Y'); return(head); } 60010 head=500 70020 p=600 NULL30 nw=700
  • 17.
    case 1: head=create(head); /*Function Call*/ break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 17 sll *create(sll *head) { sll *p,*nw; char ans; do { nw=(sll*)malloc(sizeof(sll)); nw->next=NULL; printf("nEnter the data:"); scanf("%d",&(nw->data)); if(head==NULL) p=head=nw; else { p->next=nw; p=nw; } printf("nt Do you want to insert node(Y/N)"); flushall(); scanf("%c",&ans); }while(ans=='y'||ans=='Y'); return(head); } 60010 head=500 70020 p=600 NULL30 p=nw=700
  • 18.
    case 2: head= insert(head); break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 18 sll *insert(sll *head) { sll *p,*q; int loc,i; printf("nEnter the location:"); scanf("%d",&loc); //enter location for node insertion p=(sll*)malloc(sizeof(sll)); //create new node printf("nenter a data:"); //enter data in node scanf("%d",&(p->data)); if(loc==1) //Insertion as head node i.e. if position is 1 { p->next=head; head=p; return(head); } 60010 head=500 70020 600 NULL30 700
  • 19.
    case 2: head= insert(head); break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 19 sll *insert(sll *head) { sll *p,*q; int loc,i; printf("nEnter the location:"); scanf("%d",&loc); //enter location for node insertion p=(sll*)malloc(sizeof(sll)); //create new node printf("nenter a data:"); //enter data in node scanf("%d",&(p->data)); if(loc==1) //Insertion as head node i.e. if position is 1 { p->next=head; head=p; return(head); } 60010 head=500 70020 600 NULL30 700 5 P=400
  • 20.
    case 2: head= insert(head); break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 20 sll *insert(sll *head) { sll *p,*q; int loc,i; printf("nEnter the location:"); scanf("%d",&loc); //enter location for node insertion p=(sll*)malloc(sizeof(sll)); //create new node printf("nenter a data:"); //enter data in node scanf("%d",&(p->data)); if(loc==1) //Insertion as head node i.e. if position is 1 { p->next=head; head=p; return(head); } 60010 head=500 70020 600 NULL30 700 5005 p=head=400
  • 21.
    case 2: head= insert(head); break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 21 else // if insertion is at other position than head node { i=1;q=head; while(i<loc-1) { q=q->next; i++; } p->next=q->next; q->next=p; } disp(head); return(head); } 60010 q=head=500 70020 600 NULL30 700 NULL25 p=750
  • 22.
    case 2: head= insert(head); break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 22 else // if insertion is at other position than head node { i=1;q=head; while(i<loc-1) { q=q->next; i++; } p->next=q->next; q->next=p; } disp(head); return(head); } 60010 q=head=500 70020 q=600 NULL30 700 NULL25 p=750
  • 23.
    case 2: head= insert(head); break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 23 else // if insertion is at other position than head node { i=1;q=head; while(i<loc-1) { q=q->next; i++; } p->next=q->next; q->next=p; } disp(head); return(head); } 60010 q=head=500 70020 q=600 NULL30 700 70025 p=750
  • 24.
    case 2: head= insert(head); break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 24 else // if insertion is at other position than head node { i=1;q=head; while(i<loc-1) { q=q->next; i++; } p->next=q->next; q->next=p; } disp(head); return(head); } 60010 q=head=500 75020 q=600 NULL30 700 70025 p=750
  • 25.
    case 3: head= disp(head); break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 25 void disp(sll *head) { sll *p; if(head==NULL)//if linked list is not created printf("nEmpty Linked List"); else { printf("nn Created SLL:nn "); for(p=head;p!=NULL;p=p->next) printf("%d->",p->data); printf("NULL"); } } 60010 head=500 70020 600 NULL30 700
  • 26.
    case 3: head= disp(head); break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 26 void disp(sll *head) { sll *p; if(head==NULL)//if linked list is not created printf("nEmpty Linked List"); else { printf("nn Created SLL:nn "); for(p=head;p!=NULL;p=p->next) printf("%d->",p->data); printf("NULL"); } } 60010 p=head=500 70020 600 10-> NULL30 700
  • 27.
    case 3: head= disp(head); break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 27 60010 p=head=500 70020 p=600 10->20-> NULL30 700 void disp(sll *head) { sll *p; if(head==NULL)//if linked list is not created printf("nEmpty Linked List"); else { printf("nn Created SLL:nn "); for(p=head;p!=NULL;p=p->next) printf("%d->",p->data); printf("NULL"); } }
  • 28.
    case 3: head= disp(head); break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 28 60010 p=head=500 70020 p=600 10->20->30-> NULL30 p=700 void disp(sll *head) { sll *p; if(head==NULL)//if linked list is not created printf("nEmpty Linked List"); else { printf("nn Created SLL:nn "); for(p=head;p!=NULL;p=p->next) printf("%d->",p->data); printf("NULL"); } }
  • 29.
    case 3: head= disp(head); break; InternationalInstitute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 29 60010 p=head=500 70020 p=600 10->20->30-> NULL NULL30 p=700 p=NULL void disp(sll *head) { sll *p; if(head==NULL)//if linked list is not created printf("nEmpty Linked List"); else { printf("nn Created SLL:nn "); for(p=head;p!=NULL;p=p->next) printf("%d->",p->data); printf("NULL"); } }
  • 30.
    }//end of switch-case }while(op!=6);//end of Do-while loop getch(); }//end of main function International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 30
  • 31.
    International Institute ofInformation Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Toll Free - 1800 233 4499 Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in 31
  • 32.
    ABOUT US International Instituteof Information Technology (I²IT) P-14, Rajiv Gandhi Infotech Park, Phase – 1, Hinjawadi, Pune – 411057, India International Institute of Information Technology (I²IT) was established by Late Shri. P. P. Chhabria, Founder Chairman of Finolex Group of Industries, a well-known philanthropist and former President of Mahratta Chamber of Commerce, Industries and Agriculture (MCCIA). I²IT aspires to be an academic leader recognized for innovation, quality teaching and research, holding high moral values and a forward thinking institution that explores creative approaches for the future.  Phone: +91 20 2293 3441 / 2 / 3 Toll Free Line:1800-233-4499 Fax: +91 20 2293 4191  Email: info@isquareit.edu.in  Web: www.isquareit.edu.in 32