SlideShare a Scribd company logo
1 of 13
Download to read offline
#include
#include
#include
using namespace std;
struct node
{
int val;
struct node *next;
}*startNode;
// declaring class
class LinkedList
{
public:
node* create_node(int);
void insert_last();
void sort();
void search();
void reverse();
void display();
LinkedList()
{
startNode = NULL;
}
};
// main
main()
{
int userChoice, linkedListNodes, i;
LinkedList LinkList;
startNode = NULL;
while (1)
{
// displaying menu
cout<<" 1)Insert";
cout<<"2) Remove";
cout<<"3) Search";
cout<<"4) Display";
cout<<"5) Reverse";
cout<<"6) Exit ";
// reading user choice
cout<<"Enter your userChoice : ";
cin>>userChoice;
switch(userChoice)
{
case 1:
cout<<"Inserting node to linked list: ";
LinkList.insert_begin();
cout;
break;
case 2:
cout<<"Delete element from linked list: ";
LinkList.delete();
break;
case 3:
cout<<"Searching data in linked list: ";
LinkList.search();
cout;
break;
case 4:
cout<<"Displaying linked list data: ";
LinkList.display();
cout;
break;
case 5:
cout<<"Linked list reversing: ";
LinkList.reverse();
cout;
break;
case 6:
cout<<"Exiting...";
exit(1);
break;
default:
cout<<"Enter correct userChoice";
}
}
}
// node creating to store into list
node *LinkedList::create_node(int val)
{
struct node *tempNode, *tempNode;
tempNode = new(struct node);
if (tempNode == NULL)
{
cout<<"No memory allocated ";
return 0;
}
else
{
tempNode->val = val;
tempNode->next = NULL;
return tempNode;
}
}
/*
* Inserting Node at last
*/
void LinkedList::insert_last()
{
int val;
cout<<"Enter the val to be inserted: ";
cin>>val;
struct node *tempNode, *tempNode;
tempNode = create_node(val);
tempNode = startNode;
while (tempNode->next != NULL)
{
tempNode = tempNode->next;
}
tempNode->next = NULL;
tempNode->next = tempNode;
cout<<"Element Inserted";
}
// deleting element
void LinkedList::delete()
{
int position, i, count = 0;
if (startNode == NULL)
{
cout<<"Linkedlist empty"<>position;
struct node *tempNode, *ptr;
tempNode = startNode;
if (position == 1)
{
startNode = tempNode->next;
}
else
{
while (tempNode != NULL)
{
tempNode = tempNode->next;
count++;
}
if (position > 0 && position <= count)
{
tempNode = startNode;
for (i = 1;i < position;i++)
{
ptr = tempNode;
tempNode = tempNode->next;
}
ptr->next = tempNode->next;
}
else
{
cout<<"Enter correct position";
}
}
}
// search data in linked list
void LinkedList::search()
{
int val, position = 0;
bool flagValue = false;
if (startNode == NULL)
{
cout<<"List is empty";
return;
}
cout<<"Enter the val to search: ";
cin>>val;
struct node *tempNode;
tempNode = startNode;
while (tempNode != NULL)
{
position++;
if (tempNode->val == val)
{
flagValue = true;
cout<<"Data "<next;
}
if (!flagValue)
cout<<"data not found";
}
// linkedlist reverese
void LinkedList::reverse()
{
struct node *pointer1, *pointer2, *pointer3;
if (startNode == NULL)
{
cout<<"List is empty"<next == NULL)
{
return;
}
pointer1 = startNode;
pointer2 = pointer1->next;
pointer3 = pointer2->next;
pointer1->next = NULL;
pointer2->next = pointer1;
while (pointer3 != NULL)
{
pointer1 = pointer2;
pointer2 = pointer3;
pointer3 = pointer3->next;
pointer2->next = pointer1;
}
startNode = pointer2;
}
// display list
void LinkedList::display()
{
struct node *tempNode;
if (startNode == NULL)
{
cout<<"The List is Empty";
return;
}
tempNode = startNode;
cout<<"Data in list are ";
while (tempNode != NULL)
{
cout<val<<"->";
tempNode = tempNode->next;
}
}
Solution
#include
#include
#include
using namespace std;
struct node
{
int val;
struct node *next;
}*startNode;
// declaring class
class LinkedList
{
public:
node* create_node(int);
void insert_last();
void sort();
void search();
void reverse();
void display();
LinkedList()
{
startNode = NULL;
}
};
// main
main()
{
int userChoice, linkedListNodes, i;
LinkedList LinkList;
startNode = NULL;
while (1)
{
// displaying menu
cout<<" 1)Insert";
cout<<"2) Remove";
cout<<"3) Search";
cout<<"4) Display";
cout<<"5) Reverse";
cout<<"6) Exit ";
// reading user choice
cout<<"Enter your userChoice : ";
cin>>userChoice;
switch(userChoice)
{
case 1:
cout<<"Inserting node to linked list: ";
LinkList.insert_begin();
cout;
break;
case 2:
cout<<"Delete element from linked list: ";
LinkList.delete();
break;
case 3:
cout<<"Searching data in linked list: ";
LinkList.search();
cout;
break;
case 4:
cout<<"Displaying linked list data: ";
LinkList.display();
cout;
break;
case 5:
cout<<"Linked list reversing: ";
LinkList.reverse();
cout;
break;
case 6:
cout<<"Exiting...";
exit(1);
break;
default:
cout<<"Enter correct userChoice";
}
}
}
// node creating to store into list
node *LinkedList::create_node(int val)
{
struct node *tempNode, *tempNode;
tempNode = new(struct node);
if (tempNode == NULL)
{
cout<<"No memory allocated ";
return 0;
}
else
{
tempNode->val = val;
tempNode->next = NULL;
return tempNode;
}
}
/*
* Inserting Node at last
*/
void LinkedList::insert_last()
{
int val;
cout<<"Enter the val to be inserted: ";
cin>>val;
struct node *tempNode, *tempNode;
tempNode = create_node(val);
tempNode = startNode;
while (tempNode->next != NULL)
{
tempNode = tempNode->next;
}
tempNode->next = NULL;
tempNode->next = tempNode;
cout<<"Element Inserted";
}
// deleting element
void LinkedList::delete()
{
int position, i, count = 0;
if (startNode == NULL)
{
cout<<"Linkedlist empty"<>position;
struct node *tempNode, *ptr;
tempNode = startNode;
if (position == 1)
{
startNode = tempNode->next;
}
else
{
while (tempNode != NULL)
{
tempNode = tempNode->next;
count++;
}
if (position > 0 && position <= count)
{
tempNode = startNode;
for (i = 1;i < position;i++)
{
ptr = tempNode;
tempNode = tempNode->next;
}
ptr->next = tempNode->next;
}
else
{
cout<<"Enter correct position";
}
}
}
// search data in linked list
void LinkedList::search()
{
int val, position = 0;
bool flagValue = false;
if (startNode == NULL)
{
cout<<"List is empty";
return;
}
cout<<"Enter the val to search: ";
cin>>val;
struct node *tempNode;
tempNode = startNode;
while (tempNode != NULL)
{
position++;
if (tempNode->val == val)
{
flagValue = true;
cout<<"Data "<next;
}
if (!flagValue)
cout<<"data not found";
}
// linkedlist reverese
void LinkedList::reverse()
{
struct node *pointer1, *pointer2, *pointer3;
if (startNode == NULL)
{
cout<<"List is empty"<next == NULL)
{
return;
}
pointer1 = startNode;
pointer2 = pointer1->next;
pointer3 = pointer2->next;
pointer1->next = NULL;
pointer2->next = pointer1;
while (pointer3 != NULL)
{
pointer1 = pointer2;
pointer2 = pointer3;
pointer3 = pointer3->next;
pointer2->next = pointer1;
}
startNode = pointer2;
}
// display list
void LinkedList::display()
{
struct node *tempNode;
if (startNode == NULL)
{
cout<<"The List is Empty";
return;
}
tempNode = startNode;
cout<<"Data in list are ";
while (tempNode != NULL)
{
cout<val<<"->";
tempNode = tempNode->next;
}
}

More Related Content

Similar to #includeiostream #includecstdio #includecstdlib using na.pdf

Please finish the int LLInsert function.typedef struct STUDENT {.pdf
Please finish the int LLInsert function.typedef struct STUDENT {.pdfPlease finish the int LLInsert function.typedef struct STUDENT {.pdf
Please finish the int LLInsert function.typedef struct STUDENT {.pdffortmdu
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxteyaj1
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfflashfashioncasualwe
 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfarorastores
 
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.pdfanupambedcovers
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdflakshmijewellery
 
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.pdfarjunstores123
 
Please correct my errors upvote Clears our entire .pdf
Please correct my errors upvote      Clears our entire .pdfPlease correct my errors upvote      Clears our entire .pdf
Please correct my errors upvote Clears our entire .pdfkitty811
 
Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of listElavarasi K
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfforladies
 
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdfAnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdfanwarsadath111
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docxajoy21
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdffathimafancyjeweller
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdffantoosh1
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfclimatecontrolsv
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfferoz544
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhvasavim9
 
Binary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureBinary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureZarghamullahShah
 

Similar to #includeiostream #includecstdio #includecstdlib using na.pdf (20)

Please finish the int LLInsert function.typedef struct STUDENT {.pdf
Please finish the int LLInsert function.typedef struct STUDENT {.pdfPlease finish the int LLInsert function.typedef struct STUDENT {.pdf
Please finish the int LLInsert function.typedef struct STUDENT {.pdf
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.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
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf
 
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
 
Please correct my errors upvote Clears our entire .pdf
Please correct my errors upvote      Clears our entire .pdfPlease correct my errors upvote      Clears our entire .pdf
Please correct my errors upvote Clears our entire .pdf
 
Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of list
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdfAnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdf
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
 
Binary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureBinary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structure
 
Linked Stack program.docx
Linked Stack program.docxLinked Stack program.docx
Linked Stack program.docx
 

More from harihelectronicspune

Entero pluri assay ,done to detect the enterobacteriaceae bacteria w.pdf
  Entero pluri assay ,done to detect the enterobacteriaceae bacteria w.pdf  Entero pluri assay ,done to detect the enterobacteriaceae bacteria w.pdf
Entero pluri assay ,done to detect the enterobacteriaceae bacteria w.pdfharihelectronicspune
 
steam distillation is an effective way to separat.pdf
                     steam distillation is an effective way to separat.pdf                     steam distillation is an effective way to separat.pdf
steam distillation is an effective way to separat.pdfharihelectronicspune
 
Nothing, really. Cu has a charge of 3+ or 2+ in .pdf
                     Nothing, really.  Cu has a charge of 3+ or 2+ in .pdf                     Nothing, really.  Cu has a charge of 3+ or 2+ in .pdf
Nothing, really. Cu has a charge of 3+ or 2+ in .pdfharihelectronicspune
 
2) Starter culture is the culture of microorganisms used to inoculat.pdf
2) Starter culture is the culture of microorganisms used to inoculat.pdf2) Starter culture is the culture of microorganisms used to inoculat.pdf
2) Starter culture is the culture of microorganisms used to inoculat.pdfharihelectronicspune
 
1. What were the organizational benefits for having a cloud computin.pdf
1. What were the organizational benefits for having a cloud computin.pdf1. What were the organizational benefits for having a cloud computin.pdf
1. What were the organizational benefits for having a cloud computin.pdfharihelectronicspune
 
what is x(4-3x)-7Solutionx(4-3x)-7 is just an algebraic expres.pdf
what is x(4-3x)-7Solutionx(4-3x)-7 is just an algebraic expres.pdfwhat is x(4-3x)-7Solutionx(4-3x)-7 is just an algebraic expres.pdf
what is x(4-3x)-7Solutionx(4-3x)-7 is just an algebraic expres.pdfharihelectronicspune
 
What probability value would complete the following probability dist.pdf
What probability value would complete the following probability dist.pdfWhat probability value would complete the following probability dist.pdf
What probability value would complete the following probability dist.pdfharihelectronicspune
 
TriggerTrigger is set of statements or stored program which inclu.pdf
TriggerTrigger is set of statements or stored program which inclu.pdfTriggerTrigger is set of statements or stored program which inclu.pdf
TriggerTrigger is set of statements or stored program which inclu.pdfharihelectronicspune
 
The equation isE = hcL where E is the energy, h is planc.pdf
The equation isE = hcL where E is the energy, h is planc.pdfThe equation isE = hcL where E is the energy, h is planc.pdf
The equation isE = hcL where E is the energy, h is planc.pdfharihelectronicspune
 
The white matter of the cerebellum is called arbor vitae which means.pdf
The white matter of the cerebellum is called arbor vitae which means.pdfThe white matter of the cerebellum is called arbor vitae which means.pdf
The white matter of the cerebellum is called arbor vitae which means.pdfharihelectronicspune
 
The following organs are arranged from anterior to posterior as foll.pdf
The following organs are arranged from anterior to posterior as foll.pdfThe following organs are arranged from anterior to posterior as foll.pdf
The following organs are arranged from anterior to posterior as foll.pdfharihelectronicspune
 
The Open Systems Interconnect (OSI) model has seven layers. this tex.pdf
The Open Systems Interconnect (OSI) model has seven layers. this tex.pdfThe Open Systems Interconnect (OSI) model has seven layers. this tex.pdf
The Open Systems Interconnect (OSI) model has seven layers. this tex.pdfharihelectronicspune
 
The transition in phosphorescence, from a ground singlet state to a .pdf
The transition in phosphorescence, from a ground singlet state to a .pdfThe transition in phosphorescence, from a ground singlet state to a .pdf
The transition in phosphorescence, from a ground singlet state to a .pdfharihelectronicspune
 
this is wrong the answer is 2.1 because x is small and doesnt cont.pdf
this is wrong the answer is 2.1 because x is small and doesnt cont.pdfthis is wrong the answer is 2.1 because x is small and doesnt cont.pdf
this is wrong the answer is 2.1 because x is small and doesnt cont.pdfharihelectronicspune
 
There are four basic principles required by IMA ethical standards,vi.pdf
There are four basic principles required by IMA ethical standards,vi.pdfThere are four basic principles required by IMA ethical standards,vi.pdf
There are four basic principles required by IMA ethical standards,vi.pdfharihelectronicspune
 
The synthesis of particular gene products is controlled by mechanism.pdf
The synthesis of particular gene products is controlled by mechanism.pdfThe synthesis of particular gene products is controlled by mechanism.pdf
The synthesis of particular gene products is controlled by mechanism.pdfharihelectronicspune
 
Risk assessment is the process which - identify hazards, analyzes an.pdf
Risk assessment is the process which - identify hazards, analyzes an.pdfRisk assessment is the process which - identify hazards, analyzes an.pdf
Risk assessment is the process which - identify hazards, analyzes an.pdfharihelectronicspune
 
SolutionWe will assign letters to the first column of graphs and .pdf
SolutionWe will assign letters to the first column of graphs and .pdfSolutionWe will assign letters to the first column of graphs and .pdf
SolutionWe will assign letters to the first column of graphs and .pdfharihelectronicspune
 
Solution Three of the many ways pathogens can cause tissue damage.pdf
Solution Three of the many ways pathogens can cause tissue damage.pdfSolution Three of the many ways pathogens can cause tissue damage.pdf
Solution Three of the many ways pathogens can cause tissue damage.pdfharihelectronicspune
 
Legal & Political factors having significant impact on the U.S. rest.pdf
Legal & Political factors having significant impact on the U.S. rest.pdfLegal & Political factors having significant impact on the U.S. rest.pdf
Legal & Political factors having significant impact on the U.S. rest.pdfharihelectronicspune
 

More from harihelectronicspune (20)

Entero pluri assay ,done to detect the enterobacteriaceae bacteria w.pdf
  Entero pluri assay ,done to detect the enterobacteriaceae bacteria w.pdf  Entero pluri assay ,done to detect the enterobacteriaceae bacteria w.pdf
Entero pluri assay ,done to detect the enterobacteriaceae bacteria w.pdf
 
steam distillation is an effective way to separat.pdf
                     steam distillation is an effective way to separat.pdf                     steam distillation is an effective way to separat.pdf
steam distillation is an effective way to separat.pdf
 
Nothing, really. Cu has a charge of 3+ or 2+ in .pdf
                     Nothing, really.  Cu has a charge of 3+ or 2+ in .pdf                     Nothing, really.  Cu has a charge of 3+ or 2+ in .pdf
Nothing, really. Cu has a charge of 3+ or 2+ in .pdf
 
2) Starter culture is the culture of microorganisms used to inoculat.pdf
2) Starter culture is the culture of microorganisms used to inoculat.pdf2) Starter culture is the culture of microorganisms used to inoculat.pdf
2) Starter culture is the culture of microorganisms used to inoculat.pdf
 
1. What were the organizational benefits for having a cloud computin.pdf
1. What were the organizational benefits for having a cloud computin.pdf1. What were the organizational benefits for having a cloud computin.pdf
1. What were the organizational benefits for having a cloud computin.pdf
 
what is x(4-3x)-7Solutionx(4-3x)-7 is just an algebraic expres.pdf
what is x(4-3x)-7Solutionx(4-3x)-7 is just an algebraic expres.pdfwhat is x(4-3x)-7Solutionx(4-3x)-7 is just an algebraic expres.pdf
what is x(4-3x)-7Solutionx(4-3x)-7 is just an algebraic expres.pdf
 
What probability value would complete the following probability dist.pdf
What probability value would complete the following probability dist.pdfWhat probability value would complete the following probability dist.pdf
What probability value would complete the following probability dist.pdf
 
TriggerTrigger is set of statements or stored program which inclu.pdf
TriggerTrigger is set of statements or stored program which inclu.pdfTriggerTrigger is set of statements or stored program which inclu.pdf
TriggerTrigger is set of statements or stored program which inclu.pdf
 
The equation isE = hcL where E is the energy, h is planc.pdf
The equation isE = hcL where E is the energy, h is planc.pdfThe equation isE = hcL where E is the energy, h is planc.pdf
The equation isE = hcL where E is the energy, h is planc.pdf
 
The white matter of the cerebellum is called arbor vitae which means.pdf
The white matter of the cerebellum is called arbor vitae which means.pdfThe white matter of the cerebellum is called arbor vitae which means.pdf
The white matter of the cerebellum is called arbor vitae which means.pdf
 
The following organs are arranged from anterior to posterior as foll.pdf
The following organs are arranged from anterior to posterior as foll.pdfThe following organs are arranged from anterior to posterior as foll.pdf
The following organs are arranged from anterior to posterior as foll.pdf
 
The Open Systems Interconnect (OSI) model has seven layers. this tex.pdf
The Open Systems Interconnect (OSI) model has seven layers. this tex.pdfThe Open Systems Interconnect (OSI) model has seven layers. this tex.pdf
The Open Systems Interconnect (OSI) model has seven layers. this tex.pdf
 
The transition in phosphorescence, from a ground singlet state to a .pdf
The transition in phosphorescence, from a ground singlet state to a .pdfThe transition in phosphorescence, from a ground singlet state to a .pdf
The transition in phosphorescence, from a ground singlet state to a .pdf
 
this is wrong the answer is 2.1 because x is small and doesnt cont.pdf
this is wrong the answer is 2.1 because x is small and doesnt cont.pdfthis is wrong the answer is 2.1 because x is small and doesnt cont.pdf
this is wrong the answer is 2.1 because x is small and doesnt cont.pdf
 
There are four basic principles required by IMA ethical standards,vi.pdf
There are four basic principles required by IMA ethical standards,vi.pdfThere are four basic principles required by IMA ethical standards,vi.pdf
There are four basic principles required by IMA ethical standards,vi.pdf
 
The synthesis of particular gene products is controlled by mechanism.pdf
The synthesis of particular gene products is controlled by mechanism.pdfThe synthesis of particular gene products is controlled by mechanism.pdf
The synthesis of particular gene products is controlled by mechanism.pdf
 
Risk assessment is the process which - identify hazards, analyzes an.pdf
Risk assessment is the process which - identify hazards, analyzes an.pdfRisk assessment is the process which - identify hazards, analyzes an.pdf
Risk assessment is the process which - identify hazards, analyzes an.pdf
 
SolutionWe will assign letters to the first column of graphs and .pdf
SolutionWe will assign letters to the first column of graphs and .pdfSolutionWe will assign letters to the first column of graphs and .pdf
SolutionWe will assign letters to the first column of graphs and .pdf
 
Solution Three of the many ways pathogens can cause tissue damage.pdf
Solution Three of the many ways pathogens can cause tissue damage.pdfSolution Three of the many ways pathogens can cause tissue damage.pdf
Solution Three of the many ways pathogens can cause tissue damage.pdf
 
Legal & Political factors having significant impact on the U.S. rest.pdf
Legal & Political factors having significant impact on the U.S. rest.pdfLegal & Political factors having significant impact on the U.S. rest.pdf
Legal & Political factors having significant impact on the U.S. rest.pdf
 

Recently uploaded

Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 

Recently uploaded (20)

Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 

#includeiostream #includecstdio #includecstdlib using na.pdf

  • 1. #include #include #include using namespace std; struct node { int val; struct node *next; }*startNode; // declaring class class LinkedList { public: node* create_node(int); void insert_last(); void sort(); void search(); void reverse(); void display(); LinkedList() { startNode = NULL; } }; // main main() { int userChoice, linkedListNodes, i; LinkedList LinkList; startNode = NULL; while (1) { // displaying menu
  • 2. cout<<" 1)Insert"; cout<<"2) Remove"; cout<<"3) Search"; cout<<"4) Display"; cout<<"5) Reverse"; cout<<"6) Exit "; // reading user choice cout<<"Enter your userChoice : "; cin>>userChoice; switch(userChoice) { case 1: cout<<"Inserting node to linked list: "; LinkList.insert_begin(); cout; break; case 2: cout<<"Delete element from linked list: "; LinkList.delete(); break; case 3: cout<<"Searching data in linked list: "; LinkList.search(); cout; break; case 4: cout<<"Displaying linked list data: "; LinkList.display(); cout; break; case 5: cout<<"Linked list reversing: "; LinkList.reverse(); cout; break; case 6:
  • 3. cout<<"Exiting..."; exit(1); break; default: cout<<"Enter correct userChoice"; } } } // node creating to store into list node *LinkedList::create_node(int val) { struct node *tempNode, *tempNode; tempNode = new(struct node); if (tempNode == NULL) { cout<<"No memory allocated "; return 0; } else { tempNode->val = val; tempNode->next = NULL; return tempNode; } } /* * Inserting Node at last */ void LinkedList::insert_last() { int val; cout<<"Enter the val to be inserted: "; cin>>val; struct node *tempNode, *tempNode;
  • 4. tempNode = create_node(val); tempNode = startNode; while (tempNode->next != NULL) { tempNode = tempNode->next; } tempNode->next = NULL; tempNode->next = tempNode; cout<<"Element Inserted"; } // deleting element void LinkedList::delete() { int position, i, count = 0; if (startNode == NULL) { cout<<"Linkedlist empty"<>position; struct node *tempNode, *ptr; tempNode = startNode; if (position == 1) { startNode = tempNode->next; } else { while (tempNode != NULL) { tempNode = tempNode->next; count++; } if (position > 0 && position <= count) { tempNode = startNode; for (i = 1;i < position;i++) {
  • 5. ptr = tempNode; tempNode = tempNode->next; } ptr->next = tempNode->next; } else { cout<<"Enter correct position"; } } } // search data in linked list void LinkedList::search() { int val, position = 0; bool flagValue = false; if (startNode == NULL) { cout<<"List is empty"; return; } cout<<"Enter the val to search: "; cin>>val; struct node *tempNode; tempNode = startNode; while (tempNode != NULL) { position++; if (tempNode->val == val) { flagValue = true; cout<<"Data "<next; } if (!flagValue) cout<<"data not found";
  • 6. } // linkedlist reverese void LinkedList::reverse() { struct node *pointer1, *pointer2, *pointer3; if (startNode == NULL) { cout<<"List is empty"<next == NULL) { return; } pointer1 = startNode; pointer2 = pointer1->next; pointer3 = pointer2->next; pointer1->next = NULL; pointer2->next = pointer1; while (pointer3 != NULL) { pointer1 = pointer2; pointer2 = pointer3; pointer3 = pointer3->next; pointer2->next = pointer1; } startNode = pointer2; } // display list void LinkedList::display() { struct node *tempNode; if (startNode == NULL) { cout<<"The List is Empty"; return; }
  • 7. tempNode = startNode; cout<<"Data in list are "; while (tempNode != NULL) { cout<val<<"->"; tempNode = tempNode->next; } } Solution #include #include #include using namespace std; struct node { int val; struct node *next; }*startNode; // declaring class class LinkedList { public: node* create_node(int); void insert_last(); void sort(); void search(); void reverse(); void display(); LinkedList() { startNode = NULL; } };
  • 8. // main main() { int userChoice, linkedListNodes, i; LinkedList LinkList; startNode = NULL; while (1) { // displaying menu cout<<" 1)Insert"; cout<<"2) Remove"; cout<<"3) Search"; cout<<"4) Display"; cout<<"5) Reverse"; cout<<"6) Exit "; // reading user choice cout<<"Enter your userChoice : "; cin>>userChoice; switch(userChoice) { case 1: cout<<"Inserting node to linked list: "; LinkList.insert_begin(); cout; break; case 2: cout<<"Delete element from linked list: "; LinkList.delete(); break; case 3: cout<<"Searching data in linked list: "; LinkList.search(); cout; break; case 4:
  • 9. cout<<"Displaying linked list data: "; LinkList.display(); cout; break; case 5: cout<<"Linked list reversing: "; LinkList.reverse(); cout; break; case 6: cout<<"Exiting..."; exit(1); break; default: cout<<"Enter correct userChoice"; } } } // node creating to store into list node *LinkedList::create_node(int val) { struct node *tempNode, *tempNode; tempNode = new(struct node); if (tempNode == NULL) { cout<<"No memory allocated "; return 0; } else { tempNode->val = val; tempNode->next = NULL; return tempNode; } }
  • 10. /* * Inserting Node at last */ void LinkedList::insert_last() { int val; cout<<"Enter the val to be inserted: "; cin>>val; struct node *tempNode, *tempNode; tempNode = create_node(val); tempNode = startNode; while (tempNode->next != NULL) { tempNode = tempNode->next; } tempNode->next = NULL; tempNode->next = tempNode; cout<<"Element Inserted"; } // deleting element void LinkedList::delete() { int position, i, count = 0; if (startNode == NULL) { cout<<"Linkedlist empty"<>position; struct node *tempNode, *ptr; tempNode = startNode; if (position == 1) { startNode = tempNode->next; } else {
  • 11. while (tempNode != NULL) { tempNode = tempNode->next; count++; } if (position > 0 && position <= count) { tempNode = startNode; for (i = 1;i < position;i++) { ptr = tempNode; tempNode = tempNode->next; } ptr->next = tempNode->next; } else { cout<<"Enter correct position"; } } } // search data in linked list void LinkedList::search() { int val, position = 0; bool flagValue = false; if (startNode == NULL) { cout<<"List is empty"; return; } cout<<"Enter the val to search: "; cin>>val; struct node *tempNode; tempNode = startNode;
  • 12. while (tempNode != NULL) { position++; if (tempNode->val == val) { flagValue = true; cout<<"Data "<next; } if (!flagValue) cout<<"data not found"; } // linkedlist reverese void LinkedList::reverse() { struct node *pointer1, *pointer2, *pointer3; if (startNode == NULL) { cout<<"List is empty"<next == NULL) { return; } pointer1 = startNode; pointer2 = pointer1->next; pointer3 = pointer2->next; pointer1->next = NULL; pointer2->next = pointer1; while (pointer3 != NULL) { pointer1 = pointer2; pointer2 = pointer3; pointer3 = pointer3->next; pointer2->next = pointer1; } startNode = pointer2; }
  • 13. // display list void LinkedList::display() { struct node *tempNode; if (startNode == NULL) { cout<<"The List is Empty"; return; } tempNode = startNode; cout<<"Data in list are "; while (tempNode != NULL) { cout<val<<"->"; tempNode = tempNode->next; } }