SlideShare a Scribd company logo
1 of 6
Download to read offline
Implement the unsorted single linked list as we did in the class and implement the following
operations: 1.DeletelastDuplicat(): For any element in the linked list, if there are multiple copies
(> = 2 copies), delete the last copy. DeleteSecondlastDuplicat(): For any element in the linked
list, if there are multiple copies (> = 2 copies), delete the second last copy Test your program
with the following operations: a)insert 5 b)Insert 7 c)Insert 11 d)Insert 5 e)Insert f) Insert 5 g)
Print out the list h) Delete the last duplicate of 5 i)Print out the list i) Delete the last duplicate
of 11 k) Print out the list I) Insert 11 m) Insert 7 n) Print out the list O) Delete the second last
duplicate of 5 p) Print out the list q) Delete the second last duplicate of 7 r) Print out the list
Solution
#include
#include
#include
using namespace std;
struct node
{
int data;
struct node *next;
}*start;
class LinkedList
{
public:
node* create_node(int);
void insert_begin();
void insert_pos();
void insert_last();
void delete_pos(int);
void delete_lastdup();
void delete_seclast();
int search(int);
void display();
int get_count(int);
LinkedList()
{
start = NULL;
}
};
int main()
{
int choice, pos, value, res=0;
LinkedList sl;
start = NULL;
while (1)
{
cout<>choice;
switch(choice)
{
case 1:
cout<<"Inserting Node at Beginning: "<>pos;
sl.delete_pos(pos);
break;
case 5:
cout<<"Search element in Link List: "<>value;
res=sl.search(value);
cout<<"Element "<data = value;
temp->next = NULL;
return temp;
}
}
//function to insert element at beginning
void LinkedList::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"<next != NULL)
{
if(s->data == value)
count++;
s = s->next;
}
return count;
}
//function to insert node at last
void LinkedList::insert_last()
{
int value;
cout<<"Enter the value to be inserted: ";
cin>>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"<>value;
c=get_count(value);
if(c<2)
{
cout<<"duplicate does not exist"<>value;
c=get_count(value);
x=c-1;
if(c<2)
{
cout<<"duplicate does not exist"<data == value)
{
f++;
res=pos;
if(f==x)
break;
}
s = s->next;
}
delete_pos(res);
}
}
//delete element at position
void LinkedList::delete_pos(int pos)
{
int i, counter = 0;
if (start == NULL)
{
cout<<"List is empty"<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"<data == value)
{
flag = true;
res=pos;
}
s = s->next;
}
if (!flag)
cout<<"Element "<data<<"->";
temp = temp->next;
}
cout<<"NULL"<

More Related Content

Similar to Implement the unsorted single linked list as we did in the class and .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.pdfpasqualealvarez467
 
DS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxDS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxVeerannaKotagi1
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfnitinarora01
 
To complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdfTo complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdfezycolours78
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfJUSTSTYLISH3B2MOHALI
 
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
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docxajoy21
 
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
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
 
C++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdfC++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdfsaradashata
 
C++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfC++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfaashisha5
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfmalavshah9013
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfarchgeetsenterprises
 
Background Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdfBackground Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdfaaseletronics2013
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdfKUNALHARCHANDANI1
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdffcaindore
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfvishalateen
 

Similar to Implement the unsorted single linked list as we did in the class and .pdf (20)

–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
 
DS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxDS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docx
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
 
To complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdfTo complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdf
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
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
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.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
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
C++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdfC++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdf
 
C++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfC++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdf
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
Background Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdfBackground Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdf
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
 

More from arihantstoneart

Let S = I + TT H rightarrow H, where T is linear and bounded. Show.pdf
Let S = I + TT H  rightarrow H, where T is linear and bounded. Show.pdfLet S = I + TT H  rightarrow H, where T is linear and bounded. Show.pdf
Let S = I + TT H rightarrow H, where T is linear and bounded. Show.pdfarihantstoneart
 
It is a nanotechnology question. In which you are able to pick one m.pdf
It is a nanotechnology question. In which you are able to pick one m.pdfIt is a nanotechnology question. In which you are able to pick one m.pdf
It is a nanotechnology question. In which you are able to pick one m.pdfarihantstoneart
 
I have this problem that I was given in class, but I cant for the .pdf
I have this problem that I was given in class, but I cant for the .pdfI have this problem that I was given in class, but I cant for the .pdf
I have this problem that I was given in class, but I cant for the .pdfarihantstoneart
 
Implement this in Java Method to determine if a particular elemen.pdf
Implement this in Java Method to determine if a particular elemen.pdfImplement this in Java Method to determine if a particular elemen.pdf
Implement this in Java Method to determine if a particular elemen.pdfarihantstoneart
 
If an image is represented using 400 x 300 pixels and each pixel is .pdf
If an image is represented using 400 x 300 pixels and each pixel is .pdfIf an image is represented using 400 x 300 pixels and each pixel is .pdf
If an image is represented using 400 x 300 pixels and each pixel is .pdfarihantstoneart
 
Hyposecretion of insulin is referred to as Type I diabetes insipidus.pdf
Hyposecretion of insulin is referred to as  Type I diabetes insipidus.pdfHyposecretion of insulin is referred to as  Type I diabetes insipidus.pdf
Hyposecretion of insulin is referred to as Type I diabetes insipidus.pdfarihantstoneart
 
How are the forces of diffusion and electrical force responsible for.pdf
How are the forces of diffusion and electrical force responsible for.pdfHow are the forces of diffusion and electrical force responsible for.pdf
How are the forces of diffusion and electrical force responsible for.pdfarihantstoneart
 
How does each of the differences between prokaryotes and eukaryotes .pdf
How does each of the differences between prokaryotes and eukaryotes .pdfHow does each of the differences between prokaryotes and eukaryotes .pdf
How does each of the differences between prokaryotes and eukaryotes .pdfarihantstoneart
 
For MIMO system, (a) Please talk about the advantage and disadvantag.pdf
For MIMO system, (a) Please talk about the advantage and disadvantag.pdfFor MIMO system, (a) Please talk about the advantage and disadvantag.pdf
For MIMO system, (a) Please talk about the advantage and disadvantag.pdfarihantstoneart
 
Explain why and give examples. In OO programming Polymorphism is on.pdf
Explain why and give examples. In OO programming Polymorphism is on.pdfExplain why and give examples. In OO programming Polymorphism is on.pdf
Explain why and give examples. In OO programming Polymorphism is on.pdfarihantstoneart
 
Eukaryotic cells modify RNA after transcription What critical RNA pr.pdf
Eukaryotic cells modify RNA after transcription  What critical RNA pr.pdfEukaryotic cells modify RNA after transcription  What critical RNA pr.pdf
Eukaryotic cells modify RNA after transcription What critical RNA pr.pdfarihantstoneart
 
Driverimport java.util.Scanner;A class that keeps a f.pdf
Driverimport java.util.Scanner;A class that keeps a f.pdfDriverimport java.util.Scanner;A class that keeps a f.pdf
Driverimport java.util.Scanner;A class that keeps a f.pdfarihantstoneart
 
Describe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdfDescribe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdfarihantstoneart
 
Columbus Incorporated just paid $4.3 per share dividend yesterday (i.pdf
Columbus Incorporated just paid $4.3 per share dividend yesterday (i.pdfColumbus Incorporated just paid $4.3 per share dividend yesterday (i.pdf
Columbus Incorporated just paid $4.3 per share dividend yesterday (i.pdfarihantstoneart
 
Anatomy Question Please Answer them all.A. Using a punnett square.pdf
Anatomy Question Please Answer them all.A. Using a punnett square.pdfAnatomy Question Please Answer them all.A. Using a punnett square.pdf
Anatomy Question Please Answer them all.A. Using a punnett square.pdfarihantstoneart
 
A person is lost in the desert. (S)he has no water and after a coupl.pdf
A person is lost in the desert. (S)he has no water and after a coupl.pdfA person is lost in the desert. (S)he has no water and after a coupl.pdf
A person is lost in the desert. (S)he has no water and after a coupl.pdfarihantstoneart
 
2. Describe an advantage and a limitation to tracing ancestry with b.pdf
2. Describe an advantage and a limitation to tracing ancestry with b.pdf2. Describe an advantage and a limitation to tracing ancestry with b.pdf
2. Describe an advantage and a limitation to tracing ancestry with b.pdfarihantstoneart
 
Write your thought on the following1. petroski notes that most en.pdf
Write your thought on the following1. petroski notes that most en.pdfWrite your thought on the following1. petroski notes that most en.pdf
Write your thought on the following1. petroski notes that most en.pdfarihantstoneart
 
You have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdf
You have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdfYou have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdf
You have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdfarihantstoneart
 
With X-linked inheritance, the X chromosome is transmitted in a diffe.pdf
With X-linked inheritance, the X chromosome is transmitted in a diffe.pdfWith X-linked inheritance, the X chromosome is transmitted in a diffe.pdf
With X-linked inheritance, the X chromosome is transmitted in a diffe.pdfarihantstoneart
 

More from arihantstoneart (20)

Let S = I + TT H rightarrow H, where T is linear and bounded. Show.pdf
Let S = I + TT H  rightarrow H, where T is linear and bounded. Show.pdfLet S = I + TT H  rightarrow H, where T is linear and bounded. Show.pdf
Let S = I + TT H rightarrow H, where T is linear and bounded. Show.pdf
 
It is a nanotechnology question. In which you are able to pick one m.pdf
It is a nanotechnology question. In which you are able to pick one m.pdfIt is a nanotechnology question. In which you are able to pick one m.pdf
It is a nanotechnology question. In which you are able to pick one m.pdf
 
I have this problem that I was given in class, but I cant for the .pdf
I have this problem that I was given in class, but I cant for the .pdfI have this problem that I was given in class, but I cant for the .pdf
I have this problem that I was given in class, but I cant for the .pdf
 
Implement this in Java Method to determine if a particular elemen.pdf
Implement this in Java Method to determine if a particular elemen.pdfImplement this in Java Method to determine if a particular elemen.pdf
Implement this in Java Method to determine if a particular elemen.pdf
 
If an image is represented using 400 x 300 pixels and each pixel is .pdf
If an image is represented using 400 x 300 pixels and each pixel is .pdfIf an image is represented using 400 x 300 pixels and each pixel is .pdf
If an image is represented using 400 x 300 pixels and each pixel is .pdf
 
Hyposecretion of insulin is referred to as Type I diabetes insipidus.pdf
Hyposecretion of insulin is referred to as  Type I diabetes insipidus.pdfHyposecretion of insulin is referred to as  Type I diabetes insipidus.pdf
Hyposecretion of insulin is referred to as Type I diabetes insipidus.pdf
 
How are the forces of diffusion and electrical force responsible for.pdf
How are the forces of diffusion and electrical force responsible for.pdfHow are the forces of diffusion and electrical force responsible for.pdf
How are the forces of diffusion and electrical force responsible for.pdf
 
How does each of the differences between prokaryotes and eukaryotes .pdf
How does each of the differences between prokaryotes and eukaryotes .pdfHow does each of the differences between prokaryotes and eukaryotes .pdf
How does each of the differences between prokaryotes and eukaryotes .pdf
 
For MIMO system, (a) Please talk about the advantage and disadvantag.pdf
For MIMO system, (a) Please talk about the advantage and disadvantag.pdfFor MIMO system, (a) Please talk about the advantage and disadvantag.pdf
For MIMO system, (a) Please talk about the advantage and disadvantag.pdf
 
Explain why and give examples. In OO programming Polymorphism is on.pdf
Explain why and give examples. In OO programming Polymorphism is on.pdfExplain why and give examples. In OO programming Polymorphism is on.pdf
Explain why and give examples. In OO programming Polymorphism is on.pdf
 
Eukaryotic cells modify RNA after transcription What critical RNA pr.pdf
Eukaryotic cells modify RNA after transcription  What critical RNA pr.pdfEukaryotic cells modify RNA after transcription  What critical RNA pr.pdf
Eukaryotic cells modify RNA after transcription What critical RNA pr.pdf
 
Driverimport java.util.Scanner;A class that keeps a f.pdf
Driverimport java.util.Scanner;A class that keeps a f.pdfDriverimport java.util.Scanner;A class that keeps a f.pdf
Driverimport java.util.Scanner;A class that keeps a f.pdf
 
Describe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdfDescribe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdf
 
Columbus Incorporated just paid $4.3 per share dividend yesterday (i.pdf
Columbus Incorporated just paid $4.3 per share dividend yesterday (i.pdfColumbus Incorporated just paid $4.3 per share dividend yesterday (i.pdf
Columbus Incorporated just paid $4.3 per share dividend yesterday (i.pdf
 
Anatomy Question Please Answer them all.A. Using a punnett square.pdf
Anatomy Question Please Answer them all.A. Using a punnett square.pdfAnatomy Question Please Answer them all.A. Using a punnett square.pdf
Anatomy Question Please Answer them all.A. Using a punnett square.pdf
 
A person is lost in the desert. (S)he has no water and after a coupl.pdf
A person is lost in the desert. (S)he has no water and after a coupl.pdfA person is lost in the desert. (S)he has no water and after a coupl.pdf
A person is lost in the desert. (S)he has no water and after a coupl.pdf
 
2. Describe an advantage and a limitation to tracing ancestry with b.pdf
2. Describe an advantage and a limitation to tracing ancestry with b.pdf2. Describe an advantage and a limitation to tracing ancestry with b.pdf
2. Describe an advantage and a limitation to tracing ancestry with b.pdf
 
Write your thought on the following1. petroski notes that most en.pdf
Write your thought on the following1. petroski notes that most en.pdfWrite your thought on the following1. petroski notes that most en.pdf
Write your thought on the following1. petroski notes that most en.pdf
 
You have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdf
You have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdfYou have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdf
You have two cell lines, a macrophage cell line and a CD4 T-cell lin.pdf
 
With X-linked inheritance, the X chromosome is transmitted in a diffe.pdf
With X-linked inheritance, the X chromosome is transmitted in a diffe.pdfWith X-linked inheritance, the X chromosome is transmitted in a diffe.pdf
With X-linked inheritance, the X chromosome is transmitted in a diffe.pdf
 

Recently uploaded

OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 

Recently uploaded (20)

OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Implement the unsorted single linked list as we did in the class and .pdf

  • 1. Implement the unsorted single linked list as we did in the class and implement the following operations: 1.DeletelastDuplicat(): For any element in the linked list, if there are multiple copies (> = 2 copies), delete the last copy. DeleteSecondlastDuplicat(): For any element in the linked list, if there are multiple copies (> = 2 copies), delete the second last copy Test your program with the following operations: a)insert 5 b)Insert 7 c)Insert 11 d)Insert 5 e)Insert f) Insert 5 g) Print out the list h) Delete the last duplicate of 5 i)Print out the list i) Delete the last duplicate of 11 k) Print out the list I) Insert 11 m) Insert 7 n) Print out the list O) Delete the second last duplicate of 5 p) Print out the list q) Delete the second last duplicate of 7 r) Print out the list Solution #include #include #include using namespace std; struct node { int data; struct node *next; }*start; class LinkedList { public: node* create_node(int); void insert_begin(); void insert_pos(); void insert_last(); void delete_pos(int); void delete_lastdup(); void delete_seclast(); int search(int); void display(); int get_count(int); LinkedList() { start = NULL;
  • 2. } }; int main() { int choice, pos, value, res=0; LinkedList sl; start = NULL; while (1) { cout<>choice; switch(choice) { case 1: cout<<"Inserting Node at Beginning: "<>pos; sl.delete_pos(pos); break; case 5: cout<<"Search element in Link List: "<>value; res=sl.search(value); cout<<"Element "<data = value; temp->next = NULL; return temp; } } //function to insert element at beginning void LinkedList::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;
  • 3. start->next = NULL; } else { p = start; start = temp; start->next = p; } cout<<"Element Inserted at beginning"<next != NULL) { if(s->data == value) count++; s = s->next; } return count; } //function to insert node at last void LinkedList::insert_last() { int value; cout<<"Enter the value to be inserted: "; cin>>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;
  • 4. 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"<>value; c=get_count(value);
  • 5. if(c<2) { cout<<"duplicate does not exist"<>value; c=get_count(value); x=c-1; if(c<2) { cout<<"duplicate does not exist"<data == value) { f++; res=pos; if(f==x) break; } s = s->next; } delete_pos(res); } } //delete element at position void LinkedList::delete_pos(int pos) { int i, counter = 0; if (start == NULL) { cout<<"List is empty"<next; } else { while (s != NULL) { s = s->next; counter++;
  • 6. } 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"<data == value) { flag = true; res=pos; } s = s->next; } if (!flag) cout<<"Element "<data<<"->"; temp = temp->next; } cout<<"NULL"<