Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 17, Problem 14RQE
Program Plan Intro
List or Linked list:
Linked list is a linear and dynamic data structure which is used to organize data; it contains sequence of elements which are connected together in memory to form a chain. The every element of linked list is called as a node.
List head:
List head is a pointer used to point the first node in the linked list and it is also called as “head pointer”; if the “head pointer” points to a “NULL” value, then it is considered that the “list is empty”.
Graphical representation of linked list:
The graphical representation of a linked list is as follows:
cout statement:
“cout” stands for standard output stream.
- It is the c++ stream used to access the standard output, which in this case is the output screen.
- “cout” statement is followed by the “<<” operator which is called the insertion operator.
- “<<” operator inserts the information that tails it into the stream and user can provide the required output.
endl:
- “endl” appends a new line to the output and then flushes the stream.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Given two ArrayLists: list1=[10,20,30], and list2=[40,50], what is the content of the list1 after executing the following statement: list1.addAll(list2)
a.
[40, 50]
b.
[10, 20, 30]
c.
[10, 40, 50, 20, 30]
d.
[10, 20, 30, 40, 50]
complete a C program to delete the first and the last nodes of Linked List by using given functions as below:
void Firstnodedelete();
void Lastnodedelete();
void createnodelist (int n);
void displaylist ();
Suppose myList is an object of List data structure, and myList.displayList() produces the following output:
18 17 16 28 70
What would be the output when the following statements are executed?
myList.InsertNode(3, 10);
myList.DisplayList();
Select one:
A.18 10 17 16 28 70
B.18 17 10 16 28 70
C.18 17 16 10 28 70
D.18 17 16 28 10 70
Chapter 17 Solutions
Starting Out with C++: Early Objects (9th Edition)
Ch. 17.1 - Prob. 17.1CPCh. 17.1 - Prob. 17.2CPCh. 17.1 - Prob. 17.3CPCh. 17.1 - Prob. 17.4CPCh. 17.2 - Prob. 17.5CPCh. 17.2 - Prob. 17.6CPCh. 17.2 - Why does the insertNode function shown in this...Ch. 17.2 - Prob. 17.8CPCh. 17.2 - Prob. 17.9CPCh. 17.2 - Prob. 17.10CP
Ch. 17 - Prob. 1RQECh. 17 - Prob. 2RQECh. 17 - Prob. 3RQECh. 17 - Prob. 4RQECh. 17 - Prob. 5RQECh. 17 - Prob. 6RQECh. 17 - Prob. 7RQECh. 17 - Prob. 8RQECh. 17 - Prob. 9RQECh. 17 - Write a function void printSecond(ListNode ptr}...Ch. 17 - Write a function double lastValue(ListNode ptr)...Ch. 17 - Write a function ListNode removeFirst(ListNode...Ch. 17 - Prob. 13RQECh. 17 - Prob. 14RQECh. 17 - Prob. 15RQECh. 17 - Prob. 16RQECh. 17 - Prob. 17RQECh. 17 - Prob. 18RQECh. 17 - Prob. 1PCCh. 17 - Prob. 2PCCh. 17 - Prob. 3PCCh. 17 - Prob. 4PCCh. 17 - Prob. 5PCCh. 17 - Prob. 6PCCh. 17 - Prob. 7PCCh. 17 - Prob. 8PCCh. 17 - Prob. 10PCCh. 17 - Prob. 11PCCh. 17 - Prob. 12PCCh. 17 - Running Back Program 17-11 makes a person run from...Ch. 17 - Read , Sort , Merge Using the ListNode structure...
Knowledge Booster
Similar questions
- A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings), separated by a comma. That list is followed by a name, and your program should output the phone number associated with that name. Output "None" if name is not found. Ex: If the input is: 3 Joe,123-5432 Linda,983-4123 Frank,867-5309 Frank the output is: 867-5309 Your program must define and call the following function. The return value of GetPhoneNumber is the phone number associated with the specific contact name.string GetPhoneNumber(vector<string> nameVec, vector<string> phoneNumberVec, string contactName) Hint: Use two vectors: One for the string names, and the other for the string phone numbers.arrow_forwardA)Draw the linked node structure created by the following program and , B)List the output of program. struct node{ struct node *left; char letter; struct node *right; }; typedef struct node *NODEPTR; NODEPTR getnode(void); void displayList(NODEPTR); void main() { NODEPTR p , list , save; char one; p=getnode(); p->letter='A'; list=p; p->right=p; p->left=p; save=list; for(int i=2;i<8;i+=2) { one='A'+ i; p=getnode(); p->letter=one; p->left=save; save->right=p; save=p; printf("Letter= %c\n",p->letter); } list->left=save; save->right=list; list=p; displayList(list); } void displayList(NODEPTR head) {NODEPTR save; printf("\nLIST\n"); save=head; do {printf("%c ",save->letter); save=save->left; }while(save!=head); } NODEPTR getnode() { NODEPTR q; q = (NODEPTR) malloc(sizeof(struct node));…arrow_forwardA student writes a program that for any two lists L1 and L2, computes a list L3 that contains only the elements that are common between the two lists *without duplicates*. Which following statement makes the following portion of code that computes L3 correct: L3 = [] # line 1 for elem in L1: # line 2 if elem in L2: # line 3 L3.append(elem) # line 4arrow_forward
- A ____ supports manipulation of items at any point within a linear collection. Question 5 options: dictionary list stack queuearrow_forwardConsider again a list of hourly temperature readings from a fridge, as described in Question 9. Write a program that prints the hour at which the temperature first reached its maximum value. Assume position 0 is the reading at midnight (which will be printed as 0 : 00), position 1 is the reading at 1am (1 : 00), etc. The list has at least 1 and at most 23 readings. Write the corresponding code beneath each comment. Use variable names appropriate to the problem at hand instead of the generic names used by the pattern. The first step has been done for you. Note that the output is expected to have a space before and after the colon. For example: Input Result [4.7] 0 : 00 [4.7, 3] 0 : 00 [4.7, 3, 4.8] 2 : 00 start of code followsarrow_forwarda_list = [[1, 2, 3], [3, 4, 5], [5, 6, 7]] for x in range(3): print(a_list[(2 * x + 1) % 3][(5 * x) % 3])arrow_forward
- I need a new line at the end of the new sentence3. Right now I have a good code but a space after sentence. #Define main functiondef main(): word_pairs = input()#Split words into list word_pairs = word_pairs.split()#Create lists for original and replacement words original = [] new = []#Iterate word_pair for i in range(len(word_pairs)): if i % 2 == 0: original.append(word_pairs[i]) else: new.append(word_pairs[i]) sentence = input()#Split sentence into list sentence = sentence.split() #Iterate sentence for i in range(len(sentence)):#Iterate original for j in range(len(original)):#Check to see is words match in sentence if sentence[i] == original[j]:#Replace original word with new word sentence[i] = new[j]#Print output for i in range(len(sentence)):print(sentence[i], end = " ") #Call main() functionif __name__=="__main__":main()arrow_forward) Write list comprehensions to generate the following:i) If numlist contains a list of numbers, create a new list that contains only thosenumbers that are less than 100. (e.g. [42, 130, 7, 100, 101] becomes [42, 7])ii) The numbers from 3 to 30 that are multiples of 3 (i.e. 3, 6, 9, 12, 15... 30)iii) The numbers from 3 to 30 that are multiples of both 3 and 2 (i.e. 6, 12, 18...)iv) If wordlist contains a list of strings, create a new list that has the words that startwith “p” or “P”. (e.g. [“Apple”, “pear”, “avocado”, “Pumpkin”] becomes[“pear”,”Pumpkin”] )arrow_forwardConsidering all the elements and its indexes at the right side:Write a sequence of List operations that would result to a LIST that contains ONLY the elements with its respective indexes: {index[00]=104, index[01]=165, index[02]=115, index[03]=384, index[04]=248, index[05]=117}.arrow_forward
- Given both a list x and a tuple y, write a function called sum_list_andOr_tuple that sums all the elements of both data structures and returns the sum. There is also an optional boolean argument into the function called separate which, if True, causes the function to return the sum of the list and the tuple separately (returns two values); separate is False by default. Please note that the function DOES NOT print anything - it only returns a value(s). See the sample output below: >>> my_list = [0, 9, 99]>>> my_tuple = (8, 12)>>> result = sum_list_andOr_tuple(my_list, my_tuple)>>> print(result) Output: 128>>> result = sum_list_andOr_tuple(my_list, my_tuple, separate = True)>>> print(result) Output: 108, 20arrow_forwardWrite the following function that sorts and merges two lists into a new sorted list. The new list contains only even numbers. def myMergeEvenList(list1, list2): Enter list1: 10,5,6,7 Enter list2: 12,8,5,0,1 The merged list is: 0,6,8,10,12arrow_forwardUsing the linked list, add a binary search tree function for your program that is able to search for data such as staff ID, department or name. Display the output for search results if the data exists or not exists. Example: Search: Smith ……………………………………………………………………………………………………………... Search results: ID:6134 First Name: Suzy Last Name: Smith Department: Human Resourcearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education