SlideShare a Scribd company logo
implement the ListLinked ADT (the declaration is given in ListLinked.h)(60 points)
- implement the following operations:
- constructor, assignment operator, destructor
- insert, remove, replace, clear
- isFull, isEmpty
- gotoBeginning, gotoEnd, gotoNext, gotoPrior, getCursor
implement the function moveToBeginning() that removes the data item marked by the cursor and
reinserts it at the beginning of the list
- implement the function insertBefore(..) that will insert the new data item before the cursor or if
the list is empty as the first element of the list
#include "ListLinked.h"
// ListNode member functions
template
List::ListNode::ListNode(const DataType& nodeData, ListNode* nextPtr)
{
this->dataItem = nodeData;
this->next = nextPtr;
}
// List member functions
template
List::List(int ignored = 0)
{
}
template
List::List(const List& other)
{
}
template
List& List::operator=(const List& other)
{
}
template
List::~List()
{
}
template
void List::insert(const DataType& newDataItem) throw (logic_error)
{
}
template
void List::remove() throw (logic_error)
{
}
template
void List::replace(const DataType& newDataItem) throw (logic_error)
{
}
template
void List::clear()
{
}
template
bool List::isEmpty() const
{
return false;
}
template
bool List::isFull() const
{
return false;
}
template
void List::gotoBeginning() throw (logic_error)
{
}
template
void List::gotoEnd() throw (logic_error)
{
}
template
bool List::gotoNext() throw (logic_error)
{
return false;
}
template
bool List::gotoPrior() throw (logic_error)
{
return false;
}
template
DataType List::getCursor() const throw (logic_error)
{
DataType t;
return t;
}
template
void List::moveToBeginning () throw (logic_error)
{
}
template
void List::insertBefore(const DataType& newDataItem) throw (logic_error)
{
}
#include "show5.cpp"
Solution
#include
#include
#include
using namespace std;
struct Node
{
int data;
Node *next;
};
Node *tail=NULL;
Node* Insert_atHead(Node *head, int data)
{
Node *temp=new Node;
temp->data=data;
temp->next=head;
head=temp;
return head;
}
Node* Insert_atTail(Node *head, int data)
{
Node *tail=head;
if(tail==NULL)
{
Node *temp = new Node;
temp->data=data;
temp->next=NULL;
head=temp;
return head;
}
while(tail!= NULL)
{
if(tail->next==NULL)
{
Node *temp=new Node;
temp->data=data;
temp->next=NULL;
tail->next=temp;
return tail;
}
else
{
tail=tail->next;
}
}
}
Node *Insert_atPosition(Node *head, int data, int position)
{
int i=0;
int j=position-1;
if(position==0)
{
Node *temp = new Node;
temp->data=data;
temp->next=head;
head=temp;
return head;
}
else
{
Node *temp=head;
while(inext;
i++;
}
Node *temp1 = new Node;
temp1->data=data;
temp1->next=temp->next;
temp->next=temp1;
return head;
}
return head;
}
Node* Delete(Node *head, int position)
{
Node *temp=head;
int i=1;
int j=position;
if(j==0)
{
head=head->next;
return head;
}
Node *temp1 = new Node;
while(j>0)
{
temp1=temp;
temp=temp->next;
j--;
}
temp1->next=temp->next;
delete temp;
return head;
}
int GetNode(Node *head,int positionFromTail)
{
Node *tail=head;
int l=0;
while(tail->next!=NULL)
{
tail=tail->next;
l++;
}
int i=(l-positionFromTail);
Node *temp=head;
while(i>0)
{
temp=temp->next;
i--;
}
return temp->data;
}
int Size_ofLinkedList(Node *head)
{
int S=0;
Node *temp = head;
while(temp!= NULL)
{
S++;
temp=temp->next;
}
return S;
}
Node *Reverse_LinkedList(Node *head)
{
Node *temp1 = head;
Node *tail = NULL;
Node *head1= new Node;
while(head!=NULL)
{
head1=head;
temp1=temp1->next;
head->next=tail;
tail=head;
head=temp1;
}
head=head1;
}
int CompareLists(Node *headA, Node* headB)
{
Node *tempA=headA;
Node *tempB=headB;
while(tempA!=NULL && tempB!=NULL)
{
if(tempA->data==tempB->data)
{
tempA=tempA->next;
tempB=tempB->next;
}
else
{
return 0;
}
}
if(tempA==NULL && tempB==NULL)
{
return 1;
}
else
{
return 0;
}
}
int FindMergeNode(Node *headA, Node *headB)
{
Node *tempA=headA;
Node *tempB=headB;
int m=0;
int n=0;;
while(tempA!=NULL)
{
tempA=tempA->next;
m++;
}
while(tempB!=NULL)
{
tempB=tempB->next;
n++;
}
tempA=headA;
tempB=headB;
int Data;
if(m>n)
{
int p=m-n;
while(p>0)
{
tempA=tempA->next;
p--;
}
while(tempA!=tempB)
{
tempA=tempA->next;
tempB=tempB->next;
}
Data=tempA->data;
}
else
{
int p = n-m;
while(p>0)
{
tempB=tempB->next;
p--;
}
while(tempA!=tempB)
{
tempA=tempA->next;
tempB=tempB->next;
}
Data=tempA->data;
}
return Data;
}
Node* RemoveDuplicates(Node *head)
{
Node *temp=head;
Node *temp1 = new Node;
while(temp->next!=NULL)
{
if(temp->data!=(temp->next)->data)
{
temp=temp->next;
}
else
{
temp1=temp->next;
temp->next=temp1->next;
delete temp1;
}
}
return head;
}
Node* MergeLists(Node *headA, Node* headB)
{
Node *temp = new Node;
Node *head = new Node;
if(headA==NULL || headB==NULL)
{
if(headA==NULL)
{
head=headB;
}
else
{
head=headA;
}
return head;
}
if(headA->data<=headB->data)
{
temp=headA;
headA=headA->next;
}
else
{
temp=headB;
headB=headB->next;
}
head=temp;
while(headA!=NULL && headB!=NULL)
{
if(headA->data<=headB->data)
{
temp->next=headA;
temp=temp->next;
headA=headA->next;
}
else
{
temp->next=headB;
temp=temp->next;
headB=headB->next;
}
}
if(headA==NULL && headB!=NULL)
{
temp->next=headB;
}
if(headA!=NULL && headB==NULL)
{
temp->next=headA;
}
return head;
}
int HasCycle(Node* head)
{
Node *temp1=head;
Node *temp2=head;
int X=0;
if(head==NULL || head->next==NULL)
{
X=0;
}
else
{
temp1=temp1->next;
temp2=(temp2->next)->next;
while(temp1!=temp2)
{
if(temp2->next==NULL || (temp2->next)->next==NULL)
{
X=0;
break;
}
temp1=temp1->next;
temp2=(temp2->next)->next;
X=1;
}
}
if(X==0)
{
return 0;
}
else
{
return 1;
}
}
void Print(Node *head)
{
Node *temp = head;
while(temp!= NULL)
{
cout<data<< " --> ";
temp=temp->next;
}
cout<< "NULL";
}
void ReversePrint(Node *head)
{
Node *temp1 = head;
Node *tail = NULL;
Node *head1= new Node;
if(head!=NULL)
{
while(head!=NULL)
{
head1=head;
temp1=temp1->next;
head->next=tail;
tail=head;
head=temp1;
}
Node *temp=head1;
while(temp!= NULL)
{
cout<data<< " ";
temp=temp->next;
}
}
}
int main() {
int data;
Node *head=NULL;
int H;
cout<< "No. of Node Insertion at Head: ";
cin>>H;
while(H>0)
{
cin>>data;
head=Insert_atHead(head, data);
H--;
}
int T;
cout<< "No. of Node Insertion at Tail: ";
cin>>T;
while(T>0)
{
cin>>data;
Insert_atTail(head,data);
T--;
}
int P;
cout<< " ";
cout<< "Add Node at Position: ";
cin>>P;
cout<< " ";
cout<< "data: ";
cin>>data;
Insert_atPosition(head,data,P);
cout<< " ";
cout<< "Delete Node at Position: ";
cin>>P;
Delete(head,P);
cout<< " ";
Print(head);
Reverse_LinkedList(head);
head=tail;
cout<< " ";
Print(head);
cout<< " ";
cout<< "Size of LinkedList: "<

More Related Content

Similar to implement the ListLinked ADT (the declaration is given in ListLinked.pdf

dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
ssuser0be977
 
Lab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdfLab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdf
21E135MAHIESHWARJ
 
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
nitinarora01
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
teyaj1
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
ajoy21
 
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
ezycolours78
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
AravindAnand21
 
Implement the ListArray ADT-Implement the following operations.pdf
Implement the ListArray ADT-Implement the following operations.pdfImplement the ListArray ADT-Implement the following operations.pdf
Implement the ListArray ADT-Implement the following operations.pdf
petercoiffeur18
 
Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of list
Elavarasi K
 
–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
 
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
JUSTSTYLISH3B2MOHALI
 
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
 
Linked lists
Linked listsLinked lists
Linked lists
George Scott IV
 
#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
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
ssuser7319f8
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
fastechsrv
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
Himadri Sen Gupta
 
ItemNodeh include ltiostreamgt include ltstring.pdf
ItemNodeh    include ltiostreamgt include ltstring.pdfItemNodeh    include ltiostreamgt include ltstring.pdf
ItemNodeh include ltiostreamgt include ltstring.pdf
acmefit
 

Similar to implement the ListLinked ADT (the declaration is given in ListLinked.pdf (20)

137 Lab-2.2.pdf
137 Lab-2.2.pdf137 Lab-2.2.pdf
137 Lab-2.2.pdf
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
Lab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdfLab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdf
 
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
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 
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
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
 
Implement the ListArray ADT-Implement the following operations.pdf
Implement the ListArray ADT-Implement the following operations.pdfImplement the ListArray ADT-Implement the following operations.pdf
Implement the ListArray ADT-Implement the following operations.pdf
 
Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of list
 
–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
 
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
 
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
 
Linked lists
Linked listsLinked lists
Linked lists
 
#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
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
ItemNodeh include ltiostreamgt include ltstring.pdf
ItemNodeh    include ltiostreamgt include ltstring.pdfItemNodeh    include ltiostreamgt include ltstring.pdf
ItemNodeh include ltiostreamgt include ltstring.pdf
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 

More from FOREVERPRODUCTCHD

You are asked with writing a program in C that manages contact infor.pdf
You are asked with writing a program in C that manages contact infor.pdfYou are asked with writing a program in C that manages contact infor.pdf
You are asked with writing a program in C that manages contact infor.pdf
FOREVERPRODUCTCHD
 
Write a short paragraph explaining what the exploit does in Assembly.pdf
Write a short paragraph explaining what the exploit does in Assembly.pdfWrite a short paragraph explaining what the exploit does in Assembly.pdf
Write a short paragraph explaining what the exploit does in Assembly.pdf
FOREVERPRODUCTCHD
 
Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdfWrite a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
FOREVERPRODUCTCHD
 
What quality control mechanisms should major accounting firms have i.pdf
What quality control mechanisms should major accounting firms have i.pdfWhat quality control mechanisms should major accounting firms have i.pdf
What quality control mechanisms should major accounting firms have i.pdf
FOREVERPRODUCTCHD
 
What are three basic ethical principles for journalism Why are ethi.pdf
What are three basic ethical principles for journalism Why are ethi.pdfWhat are three basic ethical principles for journalism Why are ethi.pdf
What are three basic ethical principles for journalism Why are ethi.pdf
FOREVERPRODUCTCHD
 
What are some of the different versions of UNIX® Why is it importan.pdf
What are some of the different versions of UNIX® Why is it importan.pdfWhat are some of the different versions of UNIX® Why is it importan.pdf
What are some of the different versions of UNIX® Why is it importan.pdf
FOREVERPRODUCTCHD
 
Type in your own words In details, discuss the following questions.pdf
Type in your own words In details, discuss the following questions.pdfType in your own words In details, discuss the following questions.pdf
Type in your own words In details, discuss the following questions.pdf
FOREVERPRODUCTCHD
 
Twice a first number decreased by a second number is 11. The first nu.pdf
Twice a first number decreased by a second number is 11. The first nu.pdfTwice a first number decreased by a second number is 11. The first nu.pdf
Twice a first number decreased by a second number is 11. The first nu.pdf
FOREVERPRODUCTCHD
 
the largest drum ever constructed was played at the Rotal festival H.pdf
the largest drum ever constructed was played at the Rotal festival H.pdfthe largest drum ever constructed was played at the Rotal festival H.pdf
the largest drum ever constructed was played at the Rotal festival H.pdf
FOREVERPRODUCTCHD
 
Suppose that the material that you are recrystallizing fails to perc.pdf
Suppose that the material that you are recrystallizing fails to perc.pdfSuppose that the material that you are recrystallizing fails to perc.pdf
Suppose that the material that you are recrystallizing fails to perc.pdf
FOREVERPRODUCTCHD
 
Summarize the purpose of a WAN and define what makes up a WAN connec.pdf
Summarize the purpose of a WAN and define what makes up a WAN connec.pdfSummarize the purpose of a WAN and define what makes up a WAN connec.pdf
Summarize the purpose of a WAN and define what makes up a WAN connec.pdf
FOREVERPRODUCTCHD
 
SOS Please please please help on this problem!!!!!!!!!!!!!!!!!!!!!! .pdf
SOS Please please please help on this problem!!!!!!!!!!!!!!!!!!!!!! .pdfSOS Please please please help on this problem!!!!!!!!!!!!!!!!!!!!!! .pdf
SOS Please please please help on this problem!!!!!!!!!!!!!!!!!!!!!! .pdf
FOREVERPRODUCTCHD
 
Step 12 The task is complete when the quota can be verified. Take a.pdf
Step 12  The task is complete when the quota can be verified.  Take a.pdfStep 12  The task is complete when the quota can be verified.  Take a.pdf
Step 12 The task is complete when the quota can be verified. Take a.pdf
FOREVERPRODUCTCHD
 
QUESTIONDiscuss how has Web 2.0 changed the behavior of Internet .pdf
QUESTIONDiscuss how has Web 2.0 changed the behavior of Internet .pdfQUESTIONDiscuss how has Web 2.0 changed the behavior of Internet .pdf
QUESTIONDiscuss how has Web 2.0 changed the behavior of Internet .pdf
FOREVERPRODUCTCHD
 
Python program with functions that extracts specific characters from.pdf
Python program with functions that extracts specific characters from.pdfPython program with functions that extracts specific characters from.pdf
Python program with functions that extracts specific characters from.pdf
FOREVERPRODUCTCHD
 
Please answer the following question and all its parts. Please exp.pdf
Please answer the following question and all its parts. Please exp.pdfPlease answer the following question and all its parts. Please exp.pdf
Please answer the following question and all its parts. Please exp.pdf
FOREVERPRODUCTCHD
 
Please help, I cant figure out what I did wrong. Problem 11-2A (Pa.pdf
Please help, I cant figure out what I did wrong. Problem 11-2A (Pa.pdfPlease help, I cant figure out what I did wrong. Problem 11-2A (Pa.pdf
Please help, I cant figure out what I did wrong. Problem 11-2A (Pa.pdf
FOREVERPRODUCTCHD
 
Know the different types of viruses which have a dsRNA genome A type.pdf
Know the different types of viruses which have a dsRNA genome  A type.pdfKnow the different types of viruses which have a dsRNA genome  A type.pdf
Know the different types of viruses which have a dsRNA genome A type.pdf
FOREVERPRODUCTCHD
 
In what ways do the experts foresee the use of both virtualization a.pdf
In what ways do the experts foresee the use of both virtualization a.pdfIn what ways do the experts foresee the use of both virtualization a.pdf
In what ways do the experts foresee the use of both virtualization a.pdf
FOREVERPRODUCTCHD
 
In the Meselson Stahl experiment, E. coli was grown for many generati.pdf
In the Meselson Stahl experiment, E. coli was grown for many generati.pdfIn the Meselson Stahl experiment, E. coli was grown for many generati.pdf
In the Meselson Stahl experiment, E. coli was grown for many generati.pdf
FOREVERPRODUCTCHD
 

More from FOREVERPRODUCTCHD (20)

You are asked with writing a program in C that manages contact infor.pdf
You are asked with writing a program in C that manages contact infor.pdfYou are asked with writing a program in C that manages contact infor.pdf
You are asked with writing a program in C that manages contact infor.pdf
 
Write a short paragraph explaining what the exploit does in Assembly.pdf
Write a short paragraph explaining what the exploit does in Assembly.pdfWrite a short paragraph explaining what the exploit does in Assembly.pdf
Write a short paragraph explaining what the exploit does in Assembly.pdf
 
Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdfWrite a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
 
What quality control mechanisms should major accounting firms have i.pdf
What quality control mechanisms should major accounting firms have i.pdfWhat quality control mechanisms should major accounting firms have i.pdf
What quality control mechanisms should major accounting firms have i.pdf
 
What are three basic ethical principles for journalism Why are ethi.pdf
What are three basic ethical principles for journalism Why are ethi.pdfWhat are three basic ethical principles for journalism Why are ethi.pdf
What are three basic ethical principles for journalism Why are ethi.pdf
 
What are some of the different versions of UNIX® Why is it importan.pdf
What are some of the different versions of UNIX® Why is it importan.pdfWhat are some of the different versions of UNIX® Why is it importan.pdf
What are some of the different versions of UNIX® Why is it importan.pdf
 
Type in your own words In details, discuss the following questions.pdf
Type in your own words In details, discuss the following questions.pdfType in your own words In details, discuss the following questions.pdf
Type in your own words In details, discuss the following questions.pdf
 
Twice a first number decreased by a second number is 11. The first nu.pdf
Twice a first number decreased by a second number is 11. The first nu.pdfTwice a first number decreased by a second number is 11. The first nu.pdf
Twice a first number decreased by a second number is 11. The first nu.pdf
 
the largest drum ever constructed was played at the Rotal festival H.pdf
the largest drum ever constructed was played at the Rotal festival H.pdfthe largest drum ever constructed was played at the Rotal festival H.pdf
the largest drum ever constructed was played at the Rotal festival H.pdf
 
Suppose that the material that you are recrystallizing fails to perc.pdf
Suppose that the material that you are recrystallizing fails to perc.pdfSuppose that the material that you are recrystallizing fails to perc.pdf
Suppose that the material that you are recrystallizing fails to perc.pdf
 
Summarize the purpose of a WAN and define what makes up a WAN connec.pdf
Summarize the purpose of a WAN and define what makes up a WAN connec.pdfSummarize the purpose of a WAN and define what makes up a WAN connec.pdf
Summarize the purpose of a WAN and define what makes up a WAN connec.pdf
 
SOS Please please please help on this problem!!!!!!!!!!!!!!!!!!!!!! .pdf
SOS Please please please help on this problem!!!!!!!!!!!!!!!!!!!!!! .pdfSOS Please please please help on this problem!!!!!!!!!!!!!!!!!!!!!! .pdf
SOS Please please please help on this problem!!!!!!!!!!!!!!!!!!!!!! .pdf
 
Step 12 The task is complete when the quota can be verified. Take a.pdf
Step 12  The task is complete when the quota can be verified.  Take a.pdfStep 12  The task is complete when the quota can be verified.  Take a.pdf
Step 12 The task is complete when the quota can be verified. Take a.pdf
 
QUESTIONDiscuss how has Web 2.0 changed the behavior of Internet .pdf
QUESTIONDiscuss how has Web 2.0 changed the behavior of Internet .pdfQUESTIONDiscuss how has Web 2.0 changed the behavior of Internet .pdf
QUESTIONDiscuss how has Web 2.0 changed the behavior of Internet .pdf
 
Python program with functions that extracts specific characters from.pdf
Python program with functions that extracts specific characters from.pdfPython program with functions that extracts specific characters from.pdf
Python program with functions that extracts specific characters from.pdf
 
Please answer the following question and all its parts. Please exp.pdf
Please answer the following question and all its parts. Please exp.pdfPlease answer the following question and all its parts. Please exp.pdf
Please answer the following question and all its parts. Please exp.pdf
 
Please help, I cant figure out what I did wrong. Problem 11-2A (Pa.pdf
Please help, I cant figure out what I did wrong. Problem 11-2A (Pa.pdfPlease help, I cant figure out what I did wrong. Problem 11-2A (Pa.pdf
Please help, I cant figure out what I did wrong. Problem 11-2A (Pa.pdf
 
Know the different types of viruses which have a dsRNA genome A type.pdf
Know the different types of viruses which have a dsRNA genome  A type.pdfKnow the different types of viruses which have a dsRNA genome  A type.pdf
Know the different types of viruses which have a dsRNA genome A type.pdf
 
In what ways do the experts foresee the use of both virtualization a.pdf
In what ways do the experts foresee the use of both virtualization a.pdfIn what ways do the experts foresee the use of both virtualization a.pdf
In what ways do the experts foresee the use of both virtualization a.pdf
 
In the Meselson Stahl experiment, E. coli was grown for many generati.pdf
In the Meselson Stahl experiment, E. coli was grown for many generati.pdfIn the Meselson Stahl experiment, E. coli was grown for many generati.pdf
In the Meselson Stahl experiment, E. coli was grown for many generati.pdf
 

Recently uploaded

GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 

Recently uploaded (20)

GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 

implement the ListLinked ADT (the declaration is given in ListLinked.pdf

  • 1. implement the ListLinked ADT (the declaration is given in ListLinked.h)(60 points) - implement the following operations: - constructor, assignment operator, destructor - insert, remove, replace, clear - isFull, isEmpty - gotoBeginning, gotoEnd, gotoNext, gotoPrior, getCursor implement the function moveToBeginning() that removes the data item marked by the cursor and reinserts it at the beginning of the list - implement the function insertBefore(..) that will insert the new data item before the cursor or if the list is empty as the first element of the list #include "ListLinked.h" // ListNode member functions template List::ListNode::ListNode(const DataType& nodeData, ListNode* nextPtr) { this->dataItem = nodeData; this->next = nextPtr; } // List member functions template List::List(int ignored = 0) { } template List::List(const List& other) { } template List& List::operator=(const List& other) { } template List::~List() { }
  • 2. template void List::insert(const DataType& newDataItem) throw (logic_error) { } template void List::remove() throw (logic_error) { } template void List::replace(const DataType& newDataItem) throw (logic_error) { } template void List::clear() { } template bool List::isEmpty() const { return false; } template bool List::isFull() const { return false; } template void List::gotoBeginning() throw (logic_error) { } template void List::gotoEnd() throw (logic_error) { } template bool List::gotoNext() throw (logic_error)
  • 3. { return false; } template bool List::gotoPrior() throw (logic_error) { return false; } template DataType List::getCursor() const throw (logic_error) { DataType t; return t; } template void List::moveToBeginning () throw (logic_error) { } template void List::insertBefore(const DataType& newDataItem) throw (logic_error) { } #include "show5.cpp" Solution #include #include #include using namespace std; struct Node { int data; Node *next; }; Node *tail=NULL;
  • 4. Node* Insert_atHead(Node *head, int data) { Node *temp=new Node; temp->data=data; temp->next=head; head=temp; return head; } Node* Insert_atTail(Node *head, int data) { Node *tail=head; if(tail==NULL) { Node *temp = new Node; temp->data=data; temp->next=NULL; head=temp; return head; } while(tail!= NULL) { if(tail->next==NULL) { Node *temp=new Node; temp->data=data; temp->next=NULL; tail->next=temp; return tail; } else { tail=tail->next; } } } Node *Insert_atPosition(Node *head, int data, int position)
  • 5. { int i=0; int j=position-1; if(position==0) { Node *temp = new Node; temp->data=data; temp->next=head; head=temp; return head; } else { Node *temp=head; while(inext; i++; } Node *temp1 = new Node; temp1->data=data; temp1->next=temp->next; temp->next=temp1; return head; } return head; } Node* Delete(Node *head, int position) { Node *temp=head; int i=1; int j=position; if(j==0) { head=head->next; return head; } Node *temp1 = new Node;
  • 6. while(j>0) { temp1=temp; temp=temp->next; j--; } temp1->next=temp->next; delete temp; return head; } int GetNode(Node *head,int positionFromTail) { Node *tail=head; int l=0; while(tail->next!=NULL) { tail=tail->next; l++; } int i=(l-positionFromTail); Node *temp=head; while(i>0) { temp=temp->next; i--; } return temp->data; } int Size_ofLinkedList(Node *head) { int S=0; Node *temp = head; while(temp!= NULL) { S++;
  • 7. temp=temp->next; } return S; } Node *Reverse_LinkedList(Node *head) { Node *temp1 = head; Node *tail = NULL; Node *head1= new Node; while(head!=NULL) { head1=head; temp1=temp1->next; head->next=tail; tail=head; head=temp1; } head=head1; } int CompareLists(Node *headA, Node* headB) { Node *tempA=headA; Node *tempB=headB; while(tempA!=NULL && tempB!=NULL) { if(tempA->data==tempB->data) { tempA=tempA->next; tempB=tempB->next; } else { return 0;
  • 8. } } if(tempA==NULL && tempB==NULL) { return 1; } else { return 0; } } int FindMergeNode(Node *headA, Node *headB) { Node *tempA=headA; Node *tempB=headB; int m=0; int n=0;; while(tempA!=NULL) { tempA=tempA->next; m++; } while(tempB!=NULL) { tempB=tempB->next; n++; } tempA=headA; tempB=headB; int Data; if(m>n) { int p=m-n; while(p>0) {
  • 9. tempA=tempA->next; p--; } while(tempA!=tempB) { tempA=tempA->next; tempB=tempB->next; } Data=tempA->data; } else { int p = n-m; while(p>0) { tempB=tempB->next; p--; } while(tempA!=tempB) { tempA=tempA->next; tempB=tempB->next; } Data=tempA->data; } return Data; } Node* RemoveDuplicates(Node *head) { Node *temp=head; Node *temp1 = new Node; while(temp->next!=NULL) { if(temp->data!=(temp->next)->data) {
  • 10. temp=temp->next; } else { temp1=temp->next; temp->next=temp1->next; delete temp1; } } return head; } Node* MergeLists(Node *headA, Node* headB) { Node *temp = new Node; Node *head = new Node; if(headA==NULL || headB==NULL) { if(headA==NULL) { head=headB; } else { head=headA; } return head; } if(headA->data<=headB->data) { temp=headA; headA=headA->next; } else { temp=headB;
  • 11. headB=headB->next; } head=temp; while(headA!=NULL && headB!=NULL) { if(headA->data<=headB->data) { temp->next=headA; temp=temp->next; headA=headA->next; } else { temp->next=headB; temp=temp->next; headB=headB->next; } } if(headA==NULL && headB!=NULL) { temp->next=headB; } if(headA!=NULL && headB==NULL) { temp->next=headA; } return head; } int HasCycle(Node* head) { Node *temp1=head; Node *temp2=head;
  • 12. int X=0; if(head==NULL || head->next==NULL) { X=0; } else { temp1=temp1->next; temp2=(temp2->next)->next; while(temp1!=temp2) { if(temp2->next==NULL || (temp2->next)->next==NULL) { X=0; break; } temp1=temp1->next; temp2=(temp2->next)->next; X=1; } } if(X==0) { return 0; } else { return 1; } } void Print(Node *head) {
  • 13. Node *temp = head; while(temp!= NULL) { cout<data<< " --> "; temp=temp->next; } cout<< "NULL"; } void ReversePrint(Node *head) { Node *temp1 = head; Node *tail = NULL; Node *head1= new Node; if(head!=NULL) { while(head!=NULL) { head1=head; temp1=temp1->next; head->next=tail; tail=head; head=temp1; } Node *temp=head1; while(temp!= NULL) { cout<data<< " "; temp=temp->next; } } } int main() { int data;
  • 14. Node *head=NULL; int H; cout<< "No. of Node Insertion at Head: "; cin>>H; while(H>0) { cin>>data; head=Insert_atHead(head, data); H--; } int T; cout<< "No. of Node Insertion at Tail: "; cin>>T; while(T>0) { cin>>data; Insert_atTail(head,data); T--; } int P; cout<< " "; cout<< "Add Node at Position: "; cin>>P; cout<< " "; cout<< "data: "; cin>>data; Insert_atPosition(head,data,P); cout<< " "; cout<< "Delete Node at Position: "; cin>>P; Delete(head,P); cout<< " "; Print(head); Reverse_LinkedList(head); head=tail; cout<< " ";
  • 15. Print(head); cout<< " "; cout<< "Size of LinkedList: "<