SlideShare a Scribd company logo
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

More Related Content

PDF
Binary Search - Design & Analysis of Algorithms
PPT
Singly link list
PPTX
Searching and sorting
PPTX
Binary Tree in Data Structure
PPTX
memory allocation by Novodita
PPTX
Binary Search Tree
PDF
Singly linked list
PPTX
Trees in data structures
Binary Search - Design & Analysis of Algorithms
Singly link list
Searching and sorting
Binary Tree in Data Structure
memory allocation by Novodita
Binary Search Tree
Singly linked list
Trees in data structures

What's hot (20)

PPTX
Linked List
PPTX
Doubly linked list (animated)
PPT
Linked List
PPTX
Stack and queue
PPTX
Chapter 16 Dictionaries
PPT
1.1 binary tree
PPTX
Array operations
PPTX
Data Structures - Lecture 8 [Sorting Algorithms]
PPTX
Circular link list.ppt
PPTX
Arrays In C++
PPTX
single linked list
PPTX
Stack organization
PPTX
Binary Search Tree in Data Structure
PPT
Joins in SQL
PPTX
Asymptotic notations
PPTX
Introduction to data structure ppt
PPTX
Linked list
PPT
Queue Data Structure
PPT
Binary tree
PDF
linear search and binary search
Linked List
Doubly linked list (animated)
Linked List
Stack and queue
Chapter 16 Dictionaries
1.1 binary tree
Array operations
Data Structures - Lecture 8 [Sorting Algorithms]
Circular link list.ppt
Arrays In C++
single linked list
Stack organization
Binary Search Tree in Data Structure
Joins in SQL
Asymptotic notations
Introduction to data structure ppt
Linked list
Queue Data Structure
Binary tree
linear search and binary search
Ad

Similar to Singly Linked List & Data Structure (20)

PPT
Importance of Theory of Computations
PPTX
Engineering Mathematics & Probability Distributions
PPTX
Euler’s Theorem Homogeneous Function Of Two Variables
PPTX
PPTX
Singly linked list.pptx
PPTX
What are the real differences between a wireframe, storyboard and a prototype?
PPTX
Assignement of c++
DOCX
Data structure and algorithm lab spiral (1) (4) (1).docx
PPTX
Engineering Mathematics | Maxima and Minima
DOCX
double link list in data structure
PPTX
Introduction To Assembly Language Programming
PPTX
Singly linked list program in data structure - Vtech
PPTX
Systems Programming & Operating Systems - Overview of LEX-and-YACC
DOCX
Investigatory Project for Computer Science
PDF
Program of sorting using shell sort #include stdio.h #de.pdf
Importance of Theory of Computations
Engineering Mathematics & Probability Distributions
Euler’s Theorem Homogeneous Function Of Two Variables
Singly linked list.pptx
What are the real differences between a wireframe, storyboard and a prototype?
Assignement of c++
Data structure and algorithm lab spiral (1) (4) (1).docx
Engineering Mathematics | Maxima and Minima
double link list in data structure
Introduction To Assembly Language Programming
Singly linked list program in data structure - Vtech
Systems Programming & Operating Systems - Overview of LEX-and-YACC
Investigatory Project for Computer Science
Program of sorting using shell sort #include stdio.h #de.pdf
Ad

More from International Institute of Information Technology (I²IT) (20)

PPTX
Understanding Natural Language Processing
PPTX
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
PPTX
Writing Skills: Importance of Writing Skills
PPTX
Professional Communication | Introducing Oneself
PPTX
PPTX
What Is Jenkins? Features and How It Works
PPTX
Data Science, Big Data, Data Analytics
PPTX
PPTX
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
PPTX
Sentiment Analysis in Machine Learning
PPT
Java as Object Oriented Programming Language
PPTX
PPTX
Data Visualization - How to connect Microsoft Forms to Power BI
Understanding Natural Language Processing
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
Writing Skills: Importance of Writing Skills
Professional Communication | Introducing Oneself
What Is Jenkins? Features and How It Works
Data Science, Big Data, Data Analytics
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
Sentiment Analysis in Machine Learning
Java as Object Oriented Programming Language
Data Visualization - How to connect Microsoft Forms to Power BI

Recently uploaded (20)

PPTX
Cell Types and Its function , kingdom of life
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Institutional Correction lecture only . . .
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Sports Quiz easy sports quiz sports quiz
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
Classroom Observation Tools for Teachers
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Complications of Minimal Access Surgery at WLH
Cell Types and Its function , kingdom of life
Pharmacology of Heart Failure /Pharmacotherapy of CHF
GDM (1) (1).pptx small presentation for students
Renaissance Architecture: A Journey from Faith to Humanism
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Abdominal Access Techniques with Prof. Dr. R K Mishra
Institutional Correction lecture only . . .
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Sports Quiz easy sports quiz sports quiz
STATICS OF THE RIGID BODIES Hibbelers.pdf
Pharma ospi slides which help in ospi learning
Classroom Observation Tools for Teachers
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Supply Chain Operations Speaking Notes -ICLT Program
O7-L3 Supply Chain Operations - ICLT Program
Microbial diseases, their pathogenesis and prophylaxis
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Complications of Minimal Access Surgery at WLH

Singly Linked List & Data Structure

  • 1. 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
  • 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 2
  • 3. 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
  • 4. 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.
  • 5. 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:
  • 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; 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
  • 8. 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
  • 9. 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
  • 10. 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
  • 11. 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
  • 12. 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
  • 13. 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
  • 14. 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
  • 15. 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
  • 16. 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
  • 17. 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
  • 18. 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
  • 19. 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
  • 20. 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
  • 21. 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
  • 22. 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
  • 23. 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
  • 24. 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
  • 25. 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
  • 26. 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
  • 27. 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"); } }
  • 28. 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"); } }
  • 29. 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"); } }
  • 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 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
  • 32. 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