Step 1: Write a search function called linkedlistSearch( ) that takes a number, traverse through a linked list and return true if the number exists it the list and false otherwise. Running the code should look like: Enter list numbers separated by space, followed by -1: 3 5 7 -1 Menu options: 1. Search for a value. 2. Display the sum of all numbers on the list. 3. Exit program. Your choice -> 1 Enter a value to initiate a search: 4 The number you entered does not exist in this list.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

C++

Given code

#include <iostream>
using namespace std;

class Node {
public:
int data;
Node *pNext;
};

 


void displayNumberValues( Node *pHead)
{
while( pHead != NULL) {
cout << pHead->data << " ";
pHead = pHead->pNext;
}
cout << endl;
}

 

//Option 1: Search the list
// TODO: complete the function below to search for a given value in linked lsit
// return true if value exists in the list, return false otherwise.

?? linkedlistSearch( ???)
{

}


//Option 2: get sum of all values
// TODO: complete the function below to return the sum of all elements in the linked list.

??? getSumOfAllNumbers( ???)
{

}

 

int main()
{
int userInput;
Node *pHead = NULL;
Node *pTemp;

cout<<"Enter list numbers separated by space, followed by -1: ";
cin >> userInput;

// Keep looping until end of input flag of -1 is given
while( userInput != -1) {
// Store this number on the list
pTemp = new Node;
pTemp->data = userInput;
pTemp->pNext = pHead;
pHead = pTemp;

cin >> userInput;
}

cout <<" Menu options:\n";
cout <<" 1. Search for a value. \n"
<<" 2. Display the sum of all numbers on the list. \n"
<<" 3. Exit program. \n";

cin >> userInput;
cout<<"Your choice ->" << userInput <<endl;

switch(userInput){

case(1):
int num;
cout<<"Enter a value to initiate a search:"<<endl;
cin >> num;
//Call search function here
//Display results
break;
case(2):
// Call getSumOfAllNumbers here
//Display results
break;
case(3):
exit(0);
}


return 0;
}

13.9 Lab 13: Linked Lists
This is an optional lab you can complete.
Step 1:
Write a search function called linkedlistSearch() that takes a number, traverse through a linked list and return true if the
number exists it the list and false otherwise.
Running the code should look like:
Enter list numbers separated by space, followed by -1: 3 5 7 -1
Menu options:
1. Search for a value.
2. Display the sum of all numbers on the list.
3. Exit program.
Your choice -> 1
Enter a value to initiate a search: 4
The number you entered does not exist in this list.
Another Example:
Enter list numbers separated by space, followed by -1: 3 5 7 -1
Menu options:
1. Search for a value.
2. Display the sum of all numbers on the list.
3. Exit program.
Your choice -> 1
Enter a value to initiate a search: 3
The number you entered exists in this list.
Step 2:
Write a function called getSumofAlINumbers(.) that returns the sum of all numbers in the linked list.
Running the code should look like:
Enter list numbers separated by space, followed by -1: 3 5 7 -1
Menu options:
1. Search for a value.
2. Display the sum of all numbers on the list.
3. Exit program.
Your choice -> 2
The sum of all numbers on the list is: 15
Transcribed Image Text:13.9 Lab 13: Linked Lists This is an optional lab you can complete. Step 1: Write a search function called linkedlistSearch() that takes a number, traverse through a linked list and return true if the number exists it the list and false otherwise. Running the code should look like: Enter list numbers separated by space, followed by -1: 3 5 7 -1 Menu options: 1. Search for a value. 2. Display the sum of all numbers on the list. 3. Exit program. Your choice -> 1 Enter a value to initiate a search: 4 The number you entered does not exist in this list. Another Example: Enter list numbers separated by space, followed by -1: 3 5 7 -1 Menu options: 1. Search for a value. 2. Display the sum of all numbers on the list. 3. Exit program. Your choice -> 1 Enter a value to initiate a search: 3 The number you entered exists in this list. Step 2: Write a function called getSumofAlINumbers(.) that returns the sum of all numbers in the linked list. Running the code should look like: Enter list numbers separated by space, followed by -1: 3 5 7 -1 Menu options: 1. Search for a value. 2. Display the sum of all numbers on the list. 3. Exit program. Your choice -> 2 The sum of all numbers on the list is: 15
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education