SlideShare a Scribd company logo
1 of 33
Download to read offline
1)
/*
* C++ Program to Implement Singly Linked List
*/
#include
#include
#include
using namespace std;
/*
* Node Declaration
*/
struct node
{
int info;
struct node *next;
}*start;
/*
* Class Declaration
*/
class single_llist
{
public:
node* create_node(int);
void insert_begin();
void insert_pos();
void insert_last();
void delete_pos();
void sort();
void search();
void update();
void reverse();
void display();
single_llist()
{
start = NULL;
}
};
/*
* Main :contains menu
*/
main()
{
int choice, nodes, element, position, i;
single_llist sl;
start = NULL;
while (1)
{
cout<>choice;
switch(choice)
{
case 1:
cout<<"Inserting Node at Beginning: "<info = value;
temp->next = NULL;
return temp;
}
}
/*
* Inserting element in beginning
*/
void single_llist::insert_begin()
{
int value;
cout<<"Enter the value to be inserted: ";
cin>>value;
struct node *temp, *p;
temp = create_node(value);
if (start == NULL)
{
start = temp;
start->next = NULL;
}
else
{
p = start;
start = temp;
start->next = p;
}
cout<<"Element Inserted at beginning"<>value;
struct node *temp, *s;
temp = create_node(value);
s = start;
while (s->next != NULL)
{
s = s->next;
}
temp->next = NULL;
s->next = temp;
cout<<"Element Inserted at last"<>value;
struct node *temp, *s, *ptr;
temp = create_node(value);
cout<<"Enter the postion at which node to be inserted: ";
cin>>pos;
int i;
s = start;
while (s != NULL)
{
s = s->next;
counter++;
}
if (pos == 1)
{
if (start == NULL)
{
start = temp;
start->next = NULL;
}
else
{
ptr = start;
start = temp;
start->next = ptr;
}
}
else if (pos > 1 && pos <= counter)
{
s = start;
for (i = 1; i < pos; i++)
{
ptr = s;
s = s->next;
}
ptr->next = temp;
temp->next = s;
}
else
{
cout<<"Positon out of range"<next;s !=NULL;s = s->next)
{
if (ptr->info > s->info)
{
value = ptr->info;
ptr->info = s->info;
s->info = value;
}
}
ptr = ptr->next;
}
}
/*
* Delete element at a given position
*/
void single_llist::delete_pos()
{
int pos, i, counter = 0;
if (start == NULL)
{
cout<<"List is empty"<>pos;
struct node *s, *ptr;
s = start;
if (pos == 1)
{
start = s->next;
}
else
{
while (s != NULL)
{
s = s->next;
counter++;
}
if (pos > 0 && pos <= counter)
{
s = start;
for (i = 1;i < pos;i++)
{
ptr = s;
s = s->next;
}
ptr->next = s->next;
}
else
{
cout<<"Position out of range"<>pos;
cout<<"Enter the new value: ";
cin>>value;
struct node *s, *ptr;
s = start;
if (pos == 1)
{
start->info = value;
}
else
{
for (i = 0;i < pos - 1;i++)
{
if (s == NULL)
{
cout<<"There are less than "<next;
}
s->info = value;
}
cout<<"Node Updated"<>value;
struct node *s;
s = start;
while (s != NULL)
{
pos++;
if (s->info == value)
{
flag = true;
cout<<"Element "<next;
}
if (!flag)
cout<<"Element "<next == NULL)
{
return;
}
ptr1 = start;
ptr2 = ptr1->next;
ptr3 = ptr2->next;
ptr1->next = NULL;
ptr2->next = ptr1;
while (ptr3 != NULL)
{
ptr1 = ptr2;
ptr2 = ptr3;
ptr3 = ptr3->next;
ptr2->next = ptr1;
}
start = ptr2;
}
/*
* Display Elements of a link list
*/
void single_llist::display()
{
struct node *temp;
if (start == NULL)
{
cout<<"The List is Empty"<info<<"->";
temp = temp->next;
}
cout<<"NULL"<100->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 2
Inserting node at last:
Enter the value to be inserted: 50
Element Inserted at last
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 2
Inserting node at last:
Enter the value to be inserted: 150
Element Inserted at last
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
200->100->50->150->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 3
Inserting node at a given position:
Enter the value to be inserted: 1111
Enter the position at which node to be inserted: 4
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
200->100->50->1111->150->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 3
Inserting node at a given position:
Enter the value to be inserted: 1010
Enter the position at which node to be inserted: 100
Position out of range
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
200->100->50->1111->150->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 5
Delete a Particular node:
Enter the position of value to be deleted: 1
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
100->50->1111->150->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 6
Update Node Value:
Enter the node position to be updated: 1
Enter the new value: 1010
Node Updated
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
1010->50->1111->150->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 7
Search element in Link List:
Enter the value to be searched: 50
Element 50 is found at position 2
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 9
Reverse elements of Link List
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
150->1111->50->1010->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 4
Sort Link List:
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
50->150->1010->1111->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 10
Exiting...
Solution
1)
/*
* C++ Program to Implement Singly Linked List
*/
#include
#include
#include
using namespace std;
/*
* Node Declaration
*/
struct node
{
int info;
struct node *next;
}*start;
/*
* Class Declaration
*/
class single_llist
{
public:
node* create_node(int);
void insert_begin();
void insert_pos();
void insert_last();
void delete_pos();
void sort();
void search();
void update();
void reverse();
void display();
single_llist()
{
start = NULL;
}
};
/*
* Main :contains menu
*/
main()
{
int choice, nodes, element, position, i;
single_llist sl;
start = NULL;
while (1)
{
cout<>choice;
switch(choice)
{
case 1:
cout<<"Inserting Node at Beginning: "<info = value;
temp->next = NULL;
return temp;
}
}
/*
* Inserting element in beginning
*/
void single_llist::insert_begin()
{
int value;
cout<<"Enter the value to be inserted: ";
cin>>value;
struct node *temp, *p;
temp = create_node(value);
if (start == NULL)
{
start = temp;
start->next = NULL;
}
else
{
p = start;
start = temp;
start->next = p;
}
cout<<"Element Inserted at beginning"<>value;
struct node *temp, *s;
temp = create_node(value);
s = start;
while (s->next != NULL)
{
s = s->next;
}
temp->next = NULL;
s->next = temp;
cout<<"Element Inserted at last"<>value;
struct node *temp, *s, *ptr;
temp = create_node(value);
cout<<"Enter the postion at which node to be inserted: ";
cin>>pos;
int i;
s = start;
while (s != NULL)
{
s = s->next;
counter++;
}
if (pos == 1)
{
if (start == NULL)
{
start = temp;
start->next = NULL;
}
else
{
ptr = start;
start = temp;
start->next = ptr;
}
}
else if (pos > 1 && pos <= counter)
{
s = start;
for (i = 1; i < pos; i++)
{
ptr = s;
s = s->next;
}
ptr->next = temp;
temp->next = s;
}
else
{
cout<<"Positon out of range"<next;s !=NULL;s = s->next)
{
if (ptr->info > s->info)
{
value = ptr->info;
ptr->info = s->info;
s->info = value;
}
}
ptr = ptr->next;
}
}
/*
* Delete element at a given position
*/
void single_llist::delete_pos()
{
int pos, i, counter = 0;
if (start == NULL)
{
cout<<"List is empty"<>pos;
struct node *s, *ptr;
s = start;
if (pos == 1)
{
start = s->next;
}
else
{
while (s != NULL)
{
s = s->next;
counter++;
}
if (pos > 0 && pos <= counter)
{
s = start;
for (i = 1;i < pos;i++)
{
ptr = s;
s = s->next;
}
ptr->next = s->next;
}
else
{
cout<<"Position out of range"<>pos;
cout<<"Enter the new value: ";
cin>>value;
struct node *s, *ptr;
s = start;
if (pos == 1)
{
start->info = value;
}
else
{
for (i = 0;i < pos - 1;i++)
{
if (s == NULL)
{
cout<<"There are less than "<next;
}
s->info = value;
}
cout<<"Node Updated"<>value;
struct node *s;
s = start;
while (s != NULL)
{
pos++;
if (s->info == value)
{
flag = true;
cout<<"Element "<next;
}
if (!flag)
cout<<"Element "<next == NULL)
{
return;
}
ptr1 = start;
ptr2 = ptr1->next;
ptr3 = ptr2->next;
ptr1->next = NULL;
ptr2->next = ptr1;
while (ptr3 != NULL)
{
ptr1 = ptr2;
ptr2 = ptr3;
ptr3 = ptr3->next;
ptr2->next = ptr1;
}
start = ptr2;
}
/*
* Display Elements of a link list
*/
void single_llist::display()
{
struct node *temp;
if (start == NULL)
{
cout<<"The List is Empty"<info<<"->";
temp = temp->next;
}
cout<<"NULL"<100->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 2
Inserting node at last:
Enter the value to be inserted: 50
Element Inserted at last
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 2
Inserting node at last:
Enter the value to be inserted: 150
Element Inserted at last
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
200->100->50->150->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 3
Inserting node at a given position:
Enter the value to be inserted: 1111
Enter the position at which node to be inserted: 4
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
200->100->50->1111->150->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 3
Inserting node at a given position:
Enter the value to be inserted: 1010
Enter the position at which node to be inserted: 100
Position out of range
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
200->100->50->1111->150->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 5
Delete a Particular node:
Enter the position of value to be deleted: 1
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
100->50->1111->150->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 6
Update Node Value:
Enter the node position to be updated: 1
Enter the new value: 1010
Node Updated
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
1010->50->1111->150->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 7
Search element in Link List:
Enter the value to be searched: 50
Element 50 is found at position 2
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 9
Reverse elements of Link List
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
150->1111->50->1010->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 4
Sort Link List:
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 8
Display elements of link list
Elements of list are:
50->150->1010->1111->NULL
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert Node at beginning
2.Insert node at last
3.Insert node at position
4.Sort Link List
5.Delete a Particular Node
6.Update Node Value
7.Search Element
8.Display Linked List
9.Reverse Linked List
10.Exit
Enter your choice : 10
Exiting...

More Related Content

Similar to 1) C++ Program to Implement Singly Linked List #inclu.pdf

C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
poblettesedanoree498
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
anupambedcovers
 
C++ Program to Implement Singly Linked List #includeiostream.pdf
 C++ Program to Implement Singly Linked List #includeiostream.pdf C++ Program to Implement Singly Linked List #includeiostream.pdf
C++ Program to Implement Singly Linked List #includeiostream.pdf
angelsfashion1
 
In the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfIn the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdf
arjunstores123
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
JamesPXNNewmanp
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
 
double linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdfdouble linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdf
facevenky
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
rozakashif85
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
pasqualealvarez467
 

Similar to 1) C++ Program to Implement Singly Linked List #inclu.pdf (20)

C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
 
linkrd_list.pdf
linkrd_list.pdflinkrd_list.pdf
linkrd_list.pdf
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
Singly Linked List
Singly Linked ListSingly Linked List
Singly Linked List
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked list
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
C++ Program to Implement Singly Linked List #includeiostream.pdf
 C++ Program to Implement Singly Linked List #includeiostream.pdf C++ Program to Implement Singly Linked List #includeiostream.pdf
C++ Program to Implement Singly Linked List #includeiostream.pdf
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
In the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfIn the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdf
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
 
Linked List
Linked ListLinked List
Linked List
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
double linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdfdouble linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdf
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
 
Linked list using Dynamic Memory Allocation
Linked list using Dynamic Memory AllocationLinked list using Dynamic Memory Allocation
Linked list using Dynamic Memory Allocation
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
 

More from ankitmobileshop235

#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf
ankitmobileshop235
 
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdfVi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
ankitmobileshop235
 
U.S management is trained to provide the executives their own career.pdf
U.S management is trained to provide the executives their own career.pdfU.S management is trained to provide the executives their own career.pdf
U.S management is trained to provide the executives their own career.pdf
ankitmobileshop235
 
There are many operating systemsReal-Time Operating SystemReal-t.pdf
There are many operating systemsReal-Time Operating SystemReal-t.pdfThere are many operating systemsReal-Time Operating SystemReal-t.pdf
There are many operating systemsReal-Time Operating SystemReal-t.pdf
ankitmobileshop235
 
The three major forms of business organizations are1. Sole Propri.pdf
The three major forms of business organizations are1. Sole Propri.pdfThe three major forms of business organizations are1. Sole Propri.pdf
The three major forms of business organizations are1. Sole Propri.pdf
ankitmobileshop235
 
The EVA metric effectively measures the amount of shareholder wealth.pdf
The EVA metric effectively measures the amount of shareholder wealth.pdfThe EVA metric effectively measures the amount of shareholder wealth.pdf
The EVA metric effectively measures the amount of shareholder wealth.pdf
ankitmobileshop235
 
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdfPart ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
ankitmobileshop235
 
Information is a valuable asset that can make or break your business.pdf
Information is a valuable asset that can make or break your business.pdfInformation is a valuable asset that can make or break your business.pdf
Information is a valuable asset that can make or break your business.pdf
ankitmobileshop235
 

More from ankitmobileshop235 (20)

- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf
- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf
- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf
 
#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf
 
Two sp3 orbitals are filled by lone electron pair.pdf
                     Two sp3 orbitals are filled by lone electron pair.pdf                     Two sp3 orbitals are filled by lone electron pair.pdf
Two sp3 orbitals are filled by lone electron pair.pdf
 
X-Intercept is the value of x where cross x axis. Another name is .pdf
X-Intercept is the value of x where cross x axis. Another name is .pdfX-Intercept is the value of x where cross x axis. Another name is .pdf
X-Intercept is the value of x where cross x axis. Another name is .pdf
 
whether or not the viruses is not used to classify viruses.Vir.pdf
whether or not the viruses is not used to classify viruses.Vir.pdfwhether or not the viruses is not used to classify viruses.Vir.pdf
whether or not the viruses is not used to classify viruses.Vir.pdf
 
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdfVi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
 
U.S management is trained to provide the executives their own career.pdf
U.S management is trained to provide the executives their own career.pdfU.S management is trained to provide the executives their own career.pdf
U.S management is trained to provide the executives their own career.pdf
 
There are many operating systemsReal-Time Operating SystemReal-t.pdf
There are many operating systemsReal-Time Operating SystemReal-t.pdfThere are many operating systemsReal-Time Operating SystemReal-t.pdf
There are many operating systemsReal-Time Operating SystemReal-t.pdf
 
The three major forms of business organizations are1. Sole Propri.pdf
The three major forms of business organizations are1. Sole Propri.pdfThe three major forms of business organizations are1. Sole Propri.pdf
The three major forms of business organizations are1. Sole Propri.pdf
 
the OSI model is an idea. it is abstract it has no value without imp.pdf
the OSI model is an idea. it is abstract it has no value without imp.pdfthe OSI model is an idea. it is abstract it has no value without imp.pdf
the OSI model is an idea. it is abstract it has no value without imp.pdf
 
The EVA metric effectively measures the amount of shareholder wealth.pdf
The EVA metric effectively measures the amount of shareholder wealth.pdfThe EVA metric effectively measures the amount of shareholder wealth.pdf
The EVA metric effectively measures the amount of shareholder wealth.pdf
 
Reflection about the centre of the pentagon is not its symmetric and.pdf
Reflection about the centre of the pentagon is not its symmetric and.pdfReflection about the centre of the pentagon is not its symmetric and.pdf
Reflection about the centre of the pentagon is not its symmetric and.pdf
 
Question not visible. Please state again.SolutionQuestion not .pdf
Question not visible. Please state again.SolutionQuestion not .pdfQuestion not visible. Please state again.SolutionQuestion not .pdf
Question not visible. Please state again.SolutionQuestion not .pdf
 
Per my quiz, it was also D) formation of the carbocatio or bromonium.pdf
Per my quiz, it was also D) formation of the carbocatio or bromonium.pdfPer my quiz, it was also D) formation of the carbocatio or bromonium.pdf
Per my quiz, it was also D) formation of the carbocatio or bromonium.pdf
 
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdfPart ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
 
null is a subset of every setTrueSolutionnull is a sub.pdf
null is a subset of every setTrueSolutionnull is a sub.pdfnull is a subset of every setTrueSolutionnull is a sub.pdf
null is a subset of every setTrueSolutionnull is a sub.pdf
 
LiOH Sol.pdf
                     LiOH                                      Sol.pdf                     LiOH                                      Sol.pdf
LiOH Sol.pdf
 
Information is a valuable asset that can make or break your business.pdf
Information is a valuable asset that can make or break your business.pdfInformation is a valuable asset that can make or break your business.pdf
Information is a valuable asset that can make or break your business.pdf
 
Ho there is no relationship between the age of the individual and t.pdf
Ho there is no relationship between the age of the individual and t.pdfHo there is no relationship between the age of the individual and t.pdf
Ho there is no relationship between the age of the individual and t.pdf
 
H2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdf
H2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdfH2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdf
H2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdf
 

Recently uploaded

MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 

1) C++ Program to Implement Singly Linked List #inclu.pdf

  • 1. 1) /* * C++ Program to Implement Singly Linked List */ #include #include #include using namespace std; /* * Node Declaration */ struct node { int info; struct node *next; }*start; /* * Class Declaration */ class single_llist { public: node* create_node(int); void insert_begin(); void insert_pos(); void insert_last(); void delete_pos(); void sort(); void search(); void update(); void reverse(); void display(); single_llist() {
  • 2. start = NULL; } }; /* * Main :contains menu */ main() { int choice, nodes, element, position, i; single_llist sl; start = NULL; while (1) { cout<>choice; switch(choice) { case 1: cout<<"Inserting Node at Beginning: "<info = value; temp->next = NULL; return temp; } } /* * Inserting element in beginning */ void single_llist::insert_begin() { int value; cout<<"Enter the value to be inserted: "; cin>>value; struct node *temp, *p; temp = create_node(value); if (start == NULL) {
  • 3. start = temp; start->next = NULL; } else { p = start; start = temp; start->next = p; } cout<<"Element Inserted at beginning"<>value; struct node *temp, *s; temp = create_node(value); s = start; while (s->next != NULL) { s = s->next; } temp->next = NULL; s->next = temp; cout<<"Element Inserted at last"<>value; struct node *temp, *s, *ptr; temp = create_node(value); cout<<"Enter the postion at which node to be inserted: "; cin>>pos; int i; s = start; while (s != NULL) { s = s->next; counter++; } if (pos == 1) { if (start == NULL) { start = temp;
  • 4. start->next = NULL; } else { ptr = start; start = temp; start->next = ptr; } } else if (pos > 1 && pos <= counter) { s = start; for (i = 1; i < pos; i++) { ptr = s; s = s->next; } ptr->next = temp; temp->next = s; } else { cout<<"Positon out of range"<next;s !=NULL;s = s->next) { if (ptr->info > s->info) { value = ptr->info; ptr->info = s->info; s->info = value; } } ptr = ptr->next; } } /*
  • 5. * Delete element at a given position */ void single_llist::delete_pos() { int pos, i, counter = 0; if (start == NULL) { cout<<"List is empty"<>pos; struct node *s, *ptr; s = start; if (pos == 1) { start = s->next; } else { while (s != NULL) { s = s->next; counter++; } if (pos > 0 && pos <= counter) { s = start; for (i = 1;i < pos;i++) { ptr = s; s = s->next; } ptr->next = s->next; } else { cout<<"Position out of range"<>pos; cout<<"Enter the new value: "; cin>>value;
  • 6. struct node *s, *ptr; s = start; if (pos == 1) { start->info = value; } else { for (i = 0;i < pos - 1;i++) { if (s == NULL) { cout<<"There are less than "<next; } s->info = value; } cout<<"Node Updated"<>value; struct node *s; s = start; while (s != NULL) { pos++; if (s->info == value) { flag = true; cout<<"Element "<next; } if (!flag) cout<<"Element "<next == NULL) { return; } ptr1 = start; ptr2 = ptr1->next; ptr3 = ptr2->next; ptr1->next = NULL;
  • 7. ptr2->next = ptr1; while (ptr3 != NULL) { ptr1 = ptr2; ptr2 = ptr3; ptr3 = ptr3->next; ptr2->next = ptr1; } start = ptr2; } /* * Display Elements of a link list */ void single_llist::display() { struct node *temp; if (start == NULL) { cout<<"The List is Empty"<info<<"->"; temp = temp->next; } cout<<"NULL"<100->NULL --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element
  • 8. 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 2 Inserting node at last: Enter the value to be inserted: 50 Element Inserted at last --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 2 Inserting node at last: Enter the value to be inserted: 150 Element Inserted at last --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last
  • 9. 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list Elements of list are: 200->100->50->150->NULL --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 3 Inserting node at a given position: Enter the value to be inserted: 1111 Enter the position at which node to be inserted: 4 ---------------------------------
  • 10. Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list Elements of list are: 200->100->50->1111->150->NULL --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 3 Inserting node at a given position:
  • 11. Enter the value to be inserted: 1010 Enter the position at which node to be inserted: 100 Position out of range --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list Elements of list are: 200->100->50->1111->150->NULL --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element
  • 12. 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 5 Delete a Particular node: Enter the position of value to be deleted: 1 --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list Elements of list are: 100->50->1111->150->NULL --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last
  • 13. 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 6 Update Node Value: Enter the node position to be updated: 1 Enter the new value: 1010 Node Updated --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list Elements of list are: 1010->50->1111->150->NULL ---------------------------------
  • 14. Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 7 Search element in Link List: Enter the value to be searched: 50 Element 50 is found at position 2 --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 9
  • 15. Reverse elements of Link List --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list Elements of list are: 150->1111->50->1010->NULL --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List
  • 16. 9.Reverse Linked List 10.Exit Enter your choice : 4 Sort Link List: --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list Elements of list are: 50->150->1010->1111->NULL --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node
  • 17. 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 10 Exiting... Solution 1) /* * C++ Program to Implement Singly Linked List */ #include #include #include using namespace std; /* * Node Declaration */ struct node { int info; struct node *next; }*start; /* * Class Declaration */ class single_llist { public: node* create_node(int);
  • 18. void insert_begin(); void insert_pos(); void insert_last(); void delete_pos(); void sort(); void search(); void update(); void reverse(); void display(); single_llist() { start = NULL; } }; /* * Main :contains menu */ main() { int choice, nodes, element, position, i; single_llist sl; start = NULL; while (1) { cout<>choice; switch(choice) { case 1: cout<<"Inserting Node at Beginning: "<info = value; temp->next = NULL; return temp; } } /*
  • 19. * Inserting element in beginning */ void single_llist::insert_begin() { int value; cout<<"Enter the value to be inserted: "; cin>>value; struct node *temp, *p; temp = create_node(value); if (start == NULL) { start = temp; start->next = NULL; } else { p = start; start = temp; start->next = p; } cout<<"Element Inserted at beginning"<>value; struct node *temp, *s; temp = create_node(value); s = start; while (s->next != NULL) { s = s->next; } temp->next = NULL; s->next = temp; cout<<"Element Inserted at last"<>value; struct node *temp, *s, *ptr; temp = create_node(value); cout<<"Enter the postion at which node to be inserted: "; cin>>pos; int i;
  • 20. s = start; while (s != NULL) { s = s->next; counter++; } if (pos == 1) { if (start == NULL) { start = temp; start->next = NULL; } else { ptr = start; start = temp; start->next = ptr; } } else if (pos > 1 && pos <= counter) { s = start; for (i = 1; i < pos; i++) { ptr = s; s = s->next; } ptr->next = temp; temp->next = s; } else { cout<<"Positon out of range"<next;s !=NULL;s = s->next) { if (ptr->info > s->info)
  • 21. { value = ptr->info; ptr->info = s->info; s->info = value; } } ptr = ptr->next; } } /* * Delete element at a given position */ void single_llist::delete_pos() { int pos, i, counter = 0; if (start == NULL) { cout<<"List is empty"<>pos; struct node *s, *ptr; s = start; if (pos == 1) { start = s->next; } else { while (s != NULL) { s = s->next; counter++; } if (pos > 0 && pos <= counter) { s = start; for (i = 1;i < pos;i++)
  • 22. { ptr = s; s = s->next; } ptr->next = s->next; } else { cout<<"Position out of range"<>pos; cout<<"Enter the new value: "; cin>>value; struct node *s, *ptr; s = start; if (pos == 1) { start->info = value; } else { for (i = 0;i < pos - 1;i++) { if (s == NULL) { cout<<"There are less than "<next; } s->info = value; } cout<<"Node Updated"<>value; struct node *s; s = start; while (s != NULL) { pos++; if (s->info == value) { flag = true;
  • 23. cout<<"Element "<next; } if (!flag) cout<<"Element "<next == NULL) { return; } ptr1 = start; ptr2 = ptr1->next; ptr3 = ptr2->next; ptr1->next = NULL; ptr2->next = ptr1; while (ptr3 != NULL) { ptr1 = ptr2; ptr2 = ptr3; ptr3 = ptr3->next; ptr2->next = ptr1; } start = ptr2; } /* * Display Elements of a link list */ void single_llist::display() { struct node *temp; if (start == NULL) { cout<<"The List is Empty"<info<<"->"; temp = temp->next; } cout<<"NULL"<100->NULL ---------------------------------
  • 24. Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 2 Inserting node at last: Enter the value to be inserted: 50 Element Inserted at last --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 2 Inserting node at last:
  • 25. Enter the value to be inserted: 150 Element Inserted at last --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list Elements of list are: 200->100->50->150->NULL --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element
  • 26. 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 3 Inserting node at a given position: Enter the value to be inserted: 1111 Enter the position at which node to be inserted: 4 --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list Elements of list are: 200->100->50->1111->150->NULL --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning
  • 27. 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 3 Inserting node at a given position: Enter the value to be inserted: 1010 Enter the position at which node to be inserted: 100 Position out of range --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list Elements of list are: 200->100->50->1111->150->NULL ---------------------------------
  • 28. Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 5 Delete a Particular node: Enter the position of value to be deleted: 1 --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list
  • 29. Elements of list are: 100->50->1111->150->NULL --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 6 Update Node Value: Enter the node position to be updated: 1 Enter the new value: 1010 Node Updated --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value
  • 30. 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list Elements of list are: 1010->50->1111->150->NULL --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 7 Search element in Link List: Enter the value to be searched: 50 Element 50 is found at position 2 --------------------------------- Operations on singly linked list ---------------------------------
  • 31. 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 9 Reverse elements of Link List --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list Elements of list are: 150->1111->50->1010->NULL ---------------------------------
  • 32. Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 4 Sort Link List: --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 8 Display elements of link list Elements of list are: 50->150->1010->1111->NULL
  • 33. --------------------------------- Operations on singly linked list --------------------------------- 1.Insert Node at beginning 2.Insert node at last 3.Insert node at position 4.Sort Link List 5.Delete a Particular Node 6.Update Node Value 7.Search Element 8.Display Linked List 9.Reverse Linked List 10.Exit Enter your choice : 10 Exiting...