SlideShare a Scribd company logo
1 of 6
Download to read offline
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header
file is also given. The given testfile listmain.cpp is given for demonstration of unsorted list
functionality. The functions header file is also given. Complete the functions of the header file
linked_list.h below.
=========================================================
// listmain.cpp
#include "Linked_List.h"
int main(int argc, char **argv)
{
float f;
Linked_List *theList;
cout << "Simple List Demonstration ";
cout << "(List implemented as an Array - Do not try this at home)  ";
cout << "Create a list and add a few tasks to the list";
theList = new Linked_List(); // Instantiate a list object
theList->Insert(5, 3.1f); // Note: The argument to the funtion should be a float
theList->Insert(1, 5.6f); // A constant real number like 3.1 is interpreted as
theList->Insert(3, 8.3f); // a double unless it is explicitly defined as a float
theList->Insert(2, 7.4f); // by adding an 'f' to the end of the number.
theList->Insert(4, 2.5f);
// Show what is in the list
theList->PrintList();
// Test the list length function
cout << " List now contains " << theList->ListLength() << "items.  ";
// Test delete function
cout << "Testing delete of last item in list. ";
theList->Delete(4);
theList->PrintList();
// Test delete function
cout << "Testing delete of first item in list. ";
theList->Delete(5);
theList->PrintList();
// Test delete function
cout << "Testing delete of a middle item in list. ";
theList->Delete(3);
theList->PrintList();
// Test delete function with a known failure argument
cout << "Testing failure in delete function. ";
if(theList->Delete(4))
cout << "Oops! Should not have been able to delete. ";
else
cout << "Unable to locate item to delete. ";
// Test search (known failure)
cout << "Testing Search function. Search for key 3 ";
if(theList->Search(3, &f))
cout << "Search result: theData = %f ", f;
else
cout << "Search result: Unable to locate item in list ";
// Test search (known success)
cout << "Testing Search function. Search for key 2 ";
if(theList->Search(2, &f))
cout << "Search result: theData = " << f << " ";
else
cout << "Search result: Unable to locate item in list ";
cout << "  End list demonstration...";
return 0;
}
=====================================================================
===================
// linked_list.h functions
#include
using namespace std;
// Define a structure to use as the list item
struct ListItem
{
int key;
float theData;
ListItem *next;
};
class Linked_List
{
private:
ListItem *head; // Pointer to head of the list
public:
Linked_List(); // Class constructor
~Linked_List(); // Class destuctor
void ClearList(); // Remove all items from the list
bool Insert(int key, float f);// Add an item to the list
bool Delete(int key); // Delete an item from the list
bool Search(int key, float *retVal); // Search for an item in the list
int ListLength(); // Return number of items in list
bool isEmpty(); // Return true if list is empty
bool isFull(); // Return true if list is full
void PrintList(); // Print all items in the list
};
#endif // End of list header
Solution
// linked_list.h functions
#include
using namespace std;
// Define a structure to use as the list item
struct ListItem
{
int key;
float theData;
ListItem *next;
};
class Linked_List
{
private:
// Pointer to head of the list
ListItem *head;
public:
// Class constructor
Linked_List()
{
}
// Class destuctor
~Linked_List()
{
}
// Remove all items from the list
void ClearList()
{
/* deref href to get real head */
struct node* current = *href;
struct node* next;
while (current != NULL)
{
next = current->next;
free(current);
current = next;
}
/* deref href to affect real head back
in the caller. */
*href = NULL;
}
// Add an item to the list
bool Insert(int key, float f)
{
int i;
struct ListItem *temp,*left,*right;
right=head;
for(i=1;inext;
}
temp=(struct ListItem *)malloc(sizeof(struct ListItem));
temp->data=f;
left->next=temp;
left=temp;
left->next=right;
return bool;
}
// Delete an item from the list
bool Delete(int key)
{
struct ListItem *temp, *prev;
temp=head;
while(temp!=NULL)
{
if(temp->f==f)
{
if(temp==head)
{
head=temp->next;
free(temp);
return bool;
}
else
{
prev->next=temp->next;
free(temp);
return bool;
}
}
else
{
prev=temp;
temp= temp->next;
}
}
return bool;
}
// Search for an item in the list
bool Search(int key, float *retVal)
{
}
// Return number of items in list
int ListLength();
{
struct ListItem *n;
int c=0;
n=head;
while(n!=NULL)
{
n=n->next;
c++;
}
return c;
}
bool isEmpty(); // Return true if list is empty
{
struct node *n;
int c=0;
n=head;
while(n!=NULL)
{
n=n->next;
c++;
}
if(c==0) return 1;
else 0;
}
bool isFull(); // Return true if list is full
void PrintList() // Print all items in the list
{
}
};
#endif // End of list header

More Related Content

Similar to Complete the provided partial C++ Linked List program. Main.cpp is g.pdf

Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfsravi07
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfIan5L3Allanm
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docxAdamq0DJonese
 
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfComplete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfshahidqamar17
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdfarshin9
 
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docxajoy21
 
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxBlake0FxCampbelld
 
Stack queue
Stack queueStack queue
Stack queueFraboni Ec
 
Stack queue
Stack queueStack queue
Stack queueJames Wong
 
Stack queue
Stack queueStack queue
Stack queueTony Nguyen
 
This is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdfThis is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdfinfo334223
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfmayorothenguyenhob69
 
Using C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdfUsing C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdfalokkesh1
 
you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfclearvisioneyecareno
 
helpInstructionsAdd the function max as an abstract function to .pdf
helpInstructionsAdd the function max as an abstract function to .pdfhelpInstructionsAdd the function max as an abstract function to .pdf
helpInstructionsAdd the function max as an abstract function to .pdfalmonardfans
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfmallik3000
 

Similar to Complete the provided partial C++ Linked List program. Main.cpp is g.pdf (20)

Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdf
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx
 
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfComplete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
 
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
 
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
This is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdfThis is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdf
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdf
 
Using C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdfUsing C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdf
 
you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdf
 
helpInstructionsAdd the function max as an abstract function to .pdf
helpInstructionsAdd the function max as an abstract function to .pdfhelpInstructionsAdd the function max as an abstract function to .pdf
helpInstructionsAdd the function max as an abstract function to .pdf
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
 

More from rajkumarm401

Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfrajkumarm401
 
Explain the characterstic of web service techonolgy.SolutionT.pdf
Explain the characterstic of web service techonolgy.SolutionT.pdfExplain the characterstic of web service techonolgy.SolutionT.pdf
Explain the characterstic of web service techonolgy.SolutionT.pdfrajkumarm401
 
Executive Summary i. Provide a succinct overview of your strategic p.pdf
Executive Summary i. Provide a succinct overview of your strategic p.pdfExecutive Summary i. Provide a succinct overview of your strategic p.pdf
Executive Summary i. Provide a succinct overview of your strategic p.pdfrajkumarm401
 
eee230 Instruction details Answer the following questions in a typed.pdf
eee230 Instruction details Answer the following questions in a typed.pdfeee230 Instruction details Answer the following questions in a typed.pdf
eee230 Instruction details Answer the following questions in a typed.pdfrajkumarm401
 
Essay questionPorter Combining business strategy What is itmeani.pdf
Essay questionPorter Combining business strategy What is itmeani.pdfEssay questionPorter Combining business strategy What is itmeani.pdf
Essay questionPorter Combining business strategy What is itmeani.pdfrajkumarm401
 
During oogenesis, will the genotypes of the first and second polar b.pdf
During oogenesis, will the genotypes of the first and second polar b.pdfDuring oogenesis, will the genotypes of the first and second polar b.pdf
During oogenesis, will the genotypes of the first and second polar b.pdfrajkumarm401
 
Does personal information available on the Internet make an employee.pdf
Does personal information available on the Internet make an employee.pdfDoes personal information available on the Internet make an employee.pdf
Does personal information available on the Internet make an employee.pdfrajkumarm401
 
Determine whether each series is convergent or divergent..pdf
Determine whether each series is convergent or divergent..pdfDetermine whether each series is convergent or divergent..pdf
Determine whether each series is convergent or divergent..pdfrajkumarm401
 
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdf
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdfDescribe the primary differences between WEP, WPA, and WPA2 protocol.pdf
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdfrajkumarm401
 
Click the desktop shortcut icon that you created in this module, and .pdf
Click the desktop shortcut icon that you created in this module, and .pdfClick the desktop shortcut icon that you created in this module, and .pdf
Click the desktop shortcut icon that you created in this module, and .pdfrajkumarm401
 
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdfYOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdfrajkumarm401
 
What was the causes of the Vietnam war What was the causes of .pdf
What was the causes of the Vietnam war What was the causes of .pdfWhat was the causes of the Vietnam war What was the causes of .pdf
What was the causes of the Vietnam war What was the causes of .pdfrajkumarm401
 
Transactions costs are zero in financial markets. zero in financial i.pdf
Transactions costs are zero in financial markets. zero in financial i.pdfTransactions costs are zero in financial markets. zero in financial i.pdf
Transactions costs are zero in financial markets. zero in financial i.pdfrajkumarm401
 
This is for an homework assignment using Java code. Here is the home.pdf
This is for an homework assignment using Java code. Here is the home.pdfThis is for an homework assignment using Java code. Here is the home.pdf
This is for an homework assignment using Java code. Here is the home.pdfrajkumarm401
 
Question 34 (1 point) D A check is 1) not money because it is not off.pdf
Question 34 (1 point) D A check is 1) not money because it is not off.pdfQuestion 34 (1 point) D A check is 1) not money because it is not off.pdf
Question 34 (1 point) D A check is 1) not money because it is not off.pdfrajkumarm401
 
Program Structure declare ButtonState Global variable holding statu.pdf
Program Structure declare ButtonState Global variable holding statu.pdfProgram Structure declare ButtonState Global variable holding statu.pdf
Program Structure declare ButtonState Global variable holding statu.pdfrajkumarm401
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfrajkumarm401
 
Need help in assembly. Thank you Implement the following expression .pdf
Need help in assembly. Thank you Implement the following expression .pdfNeed help in assembly. Thank you Implement the following expression .pdf
Need help in assembly. Thank you Implement the following expression .pdfrajkumarm401
 
mine whether the following s are true or false False A parabola has e.pdf
mine whether the following s are true or false False A parabola has e.pdfmine whether the following s are true or false False A parabola has e.pdf
mine whether the following s are true or false False A parabola has e.pdfrajkumarm401
 
Locate an article where the technique of Polymerase chain reaction (.pdf
Locate an article where the technique of Polymerase chain reaction (.pdfLocate an article where the technique of Polymerase chain reaction (.pdf
Locate an article where the technique of Polymerase chain reaction (.pdfrajkumarm401
 

More from rajkumarm401 (20)

Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdf
 
Explain the characterstic of web service techonolgy.SolutionT.pdf
Explain the characterstic of web service techonolgy.SolutionT.pdfExplain the characterstic of web service techonolgy.SolutionT.pdf
Explain the characterstic of web service techonolgy.SolutionT.pdf
 
Executive Summary i. Provide a succinct overview of your strategic p.pdf
Executive Summary i. Provide a succinct overview of your strategic p.pdfExecutive Summary i. Provide a succinct overview of your strategic p.pdf
Executive Summary i. Provide a succinct overview of your strategic p.pdf
 
eee230 Instruction details Answer the following questions in a typed.pdf
eee230 Instruction details Answer the following questions in a typed.pdfeee230 Instruction details Answer the following questions in a typed.pdf
eee230 Instruction details Answer the following questions in a typed.pdf
 
Essay questionPorter Combining business strategy What is itmeani.pdf
Essay questionPorter Combining business strategy What is itmeani.pdfEssay questionPorter Combining business strategy What is itmeani.pdf
Essay questionPorter Combining business strategy What is itmeani.pdf
 
During oogenesis, will the genotypes of the first and second polar b.pdf
During oogenesis, will the genotypes of the first and second polar b.pdfDuring oogenesis, will the genotypes of the first and second polar b.pdf
During oogenesis, will the genotypes of the first and second polar b.pdf
 
Does personal information available on the Internet make an employee.pdf
Does personal information available on the Internet make an employee.pdfDoes personal information available on the Internet make an employee.pdf
Does personal information available on the Internet make an employee.pdf
 
Determine whether each series is convergent or divergent..pdf
Determine whether each series is convergent or divergent..pdfDetermine whether each series is convergent or divergent..pdf
Determine whether each series is convergent or divergent..pdf
 
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdf
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdfDescribe the primary differences between WEP, WPA, and WPA2 protocol.pdf
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdf
 
Click the desktop shortcut icon that you created in this module, and .pdf
Click the desktop shortcut icon that you created in this module, and .pdfClick the desktop shortcut icon that you created in this module, and .pdf
Click the desktop shortcut icon that you created in this module, and .pdf
 
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdfYOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
 
What was the causes of the Vietnam war What was the causes of .pdf
What was the causes of the Vietnam war What was the causes of .pdfWhat was the causes of the Vietnam war What was the causes of .pdf
What was the causes of the Vietnam war What was the causes of .pdf
 
Transactions costs are zero in financial markets. zero in financial i.pdf
Transactions costs are zero in financial markets. zero in financial i.pdfTransactions costs are zero in financial markets. zero in financial i.pdf
Transactions costs are zero in financial markets. zero in financial i.pdf
 
This is for an homework assignment using Java code. Here is the home.pdf
This is for an homework assignment using Java code. Here is the home.pdfThis is for an homework assignment using Java code. Here is the home.pdf
This is for an homework assignment using Java code. Here is the home.pdf
 
Question 34 (1 point) D A check is 1) not money because it is not off.pdf
Question 34 (1 point) D A check is 1) not money because it is not off.pdfQuestion 34 (1 point) D A check is 1) not money because it is not off.pdf
Question 34 (1 point) D A check is 1) not money because it is not off.pdf
 
Program Structure declare ButtonState Global variable holding statu.pdf
Program Structure declare ButtonState Global variable holding statu.pdfProgram Structure declare ButtonState Global variable holding statu.pdf
Program Structure declare ButtonState Global variable holding statu.pdf
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
 
Need help in assembly. Thank you Implement the following expression .pdf
Need help in assembly. Thank you Implement the following expression .pdfNeed help in assembly. Thank you Implement the following expression .pdf
Need help in assembly. Thank you Implement the following expression .pdf
 
mine whether the following s are true or false False A parabola has e.pdf
mine whether the following s are true or false False A parabola has e.pdfmine whether the following s are true or false False A parabola has e.pdf
mine whether the following s are true or false False A parabola has e.pdf
 
Locate an article where the technique of Polymerase chain reaction (.pdf
Locate an article where the technique of Polymerase chain reaction (.pdfLocate an article where the technique of Polymerase chain reaction (.pdf
Locate an article where the technique of Polymerase chain reaction (.pdf
 

Recently uploaded

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
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
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
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
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
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
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
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
 
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
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
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
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
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
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
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
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
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 ...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.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
 
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
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
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
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 

Complete the provided partial C++ Linked List program. Main.cpp is g.pdf

  • 1. Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header file is also given. The given testfile listmain.cpp is given for demonstration of unsorted list functionality. The functions header file is also given. Complete the functions of the header file linked_list.h below. ========================================================= // listmain.cpp #include "Linked_List.h" int main(int argc, char **argv) { float f; Linked_List *theList; cout << "Simple List Demonstration "; cout << "(List implemented as an Array - Do not try this at home) "; cout << "Create a list and add a few tasks to the list"; theList = new Linked_List(); // Instantiate a list object theList->Insert(5, 3.1f); // Note: The argument to the funtion should be a float theList->Insert(1, 5.6f); // A constant real number like 3.1 is interpreted as theList->Insert(3, 8.3f); // a double unless it is explicitly defined as a float theList->Insert(2, 7.4f); // by adding an 'f' to the end of the number. theList->Insert(4, 2.5f); // Show what is in the list theList->PrintList(); // Test the list length function cout << " List now contains " << theList->ListLength() << "items. "; // Test delete function cout << "Testing delete of last item in list. "; theList->Delete(4); theList->PrintList(); // Test delete function cout << "Testing delete of first item in list. "; theList->Delete(5); theList->PrintList(); // Test delete function cout << "Testing delete of a middle item in list. "; theList->Delete(3);
  • 2. theList->PrintList(); // Test delete function with a known failure argument cout << "Testing failure in delete function. "; if(theList->Delete(4)) cout << "Oops! Should not have been able to delete. "; else cout << "Unable to locate item to delete. "; // Test search (known failure) cout << "Testing Search function. Search for key 3 "; if(theList->Search(3, &f)) cout << "Search result: theData = %f ", f; else cout << "Search result: Unable to locate item in list "; // Test search (known success) cout << "Testing Search function. Search for key 2 "; if(theList->Search(2, &f)) cout << "Search result: theData = " << f << " "; else cout << "Search result: Unable to locate item in list "; cout << " End list demonstration..."; return 0; } ===================================================================== =================== // linked_list.h functions #include using namespace std; // Define a structure to use as the list item struct ListItem { int key; float theData; ListItem *next; }; class Linked_List {
  • 3. private: ListItem *head; // Pointer to head of the list public: Linked_List(); // Class constructor ~Linked_List(); // Class destuctor void ClearList(); // Remove all items from the list bool Insert(int key, float f);// Add an item to the list bool Delete(int key); // Delete an item from the list bool Search(int key, float *retVal); // Search for an item in the list int ListLength(); // Return number of items in list bool isEmpty(); // Return true if list is empty bool isFull(); // Return true if list is full void PrintList(); // Print all items in the list }; #endif // End of list header Solution // linked_list.h functions #include using namespace std; // Define a structure to use as the list item struct ListItem { int key; float theData; ListItem *next; }; class Linked_List { private: // Pointer to head of the list ListItem *head; public: // Class constructor Linked_List()
  • 4. { } // Class destuctor ~Linked_List() { } // Remove all items from the list void ClearList() { /* deref href to get real head */ struct node* current = *href; struct node* next; while (current != NULL) { next = current->next; free(current); current = next; } /* deref href to affect real head back in the caller. */ *href = NULL; } // Add an item to the list bool Insert(int key, float f) { int i; struct ListItem *temp,*left,*right; right=head; for(i=1;inext; } temp=(struct ListItem *)malloc(sizeof(struct ListItem)); temp->data=f; left->next=temp; left=temp; left->next=right;
  • 5. return bool; } // Delete an item from the list bool Delete(int key) { struct ListItem *temp, *prev; temp=head; while(temp!=NULL) { if(temp->f==f) { if(temp==head) { head=temp->next; free(temp); return bool; } else { prev->next=temp->next; free(temp); return bool; } } else { prev=temp; temp= temp->next; } } return bool; } // Search for an item in the list bool Search(int key, float *retVal) { }
  • 6. // Return number of items in list int ListLength(); { struct ListItem *n; int c=0; n=head; while(n!=NULL) { n=n->next; c++; } return c; } bool isEmpty(); // Return true if list is empty { struct node *n; int c=0; n=head; while(n!=NULL) { n=n->next; c++; } if(c==0) return 1; else 0; } bool isFull(); // Return true if list is full void PrintList() // Print all items in the list { } }; #endif // End of list header