Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 17, Problem 14PC

Read , Sort , Merge

Using the ListNode structure of Program 17-2, write the following functions:

ListNode *read()

ListNode *sort(ListNode* list1)

ListNode *merge(ListNode* list1, ListNode* list2)

The first function reads a sequence of whitespace-separated positive numbers and forms the numbers read into a linked list of nodes. The input for a sequence of numbers is terminated by - 1. The second function sorts a linked list of nodes and returns a pointer to the head of the sorted lists. The function should sort by rearranging existing nodes, not by making copies of existing nodes. The third function merges two linked lists that are already sorted into a linked list that is also sorted. The merge function should not make copies of nodes: Rather, it must remove nodes from the two lists and form those nodes into a new list.

Test your functions by having the user enter two sequences of numbers, sorting each sequence, and then merging and printing the resulting list.

Blurred answer
Students have asked these similar questions
Insert and merge: Write a function insert_and_merge : (’a * int) list -> ’a * int -> (’ a * int) list = that takes a (’a * int) list, sorted in increasing order with respect to the first tuple value we call the key, and an element ’a * int. The function inserts the element at the appropriate position so the list remains sorted and outputs said list. Assume there are no duplicate keys and thus if the new element has the same key as another element in the list, the function sums their values instead. Sorting the list is not allowed.  (in oCaml)
Topic: Singly Linked ListImplement the following functions in C++ program. Read the question carefully. Below are the "CODE THAT NEEDS TO BE IMPROVED" or "NOT FINAL CODE"  (See attached photo for reference)  int add(int num) This will add the element num into the linked list and return the position of the newly-added element. In the above example, having add(60) will return 5 as it is the fifth position in the list. int remove(int num) This will remove the first instance of the element and return the position of the removed element. In the above example, having remove(40) will return 3 as 40 was the third element in the linked list before having removed. int get(int pos) This method will get the element at the specified position. This will return -1 if the specified position is invalid.   int add(int num) {             addTail(num);             return index;         }           int remove(int num) {             node* currnode = head;             node* prevnode = NULL;…
PLEASE DO NOT USE BUILT IN FILES OR FUNCTIONS! Write a program in c++ and make sure it works, that reads a list of students (first names only) from a file. It is possible for the names tobe in unsorted order in the file but they have to be placed in sorted order within the linked list.The program should use a doubly linked list.Each node in the doubly linked list should have the student’s name, a pointer to the next student, and apointer to the previous student. Here is a sample visual. The head points to the beginning of the list. Thetail points to the end of the list.When inserting consider all the following conditions:if(!head){ //no other nodes}else if (strcmp(data, head->name)<0){ //smaller than head}else if (strcmp(data, tail->name)>0){ //larger than tail}else{ //somewhere in the middle}               When deleting a student consider all the following conditions:student may be at the head, the tail or in the middleBelow, you will find a sample of what the…
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Introduction to Linked List; Author: Neso Academy;https://www.youtube.com/watch?v=R9PTBwOzceo;License: Standard YouTube License, CC-BY
Linked list | Single, Double & Circular | Data Structures | Lec-23 | Bhanu Priya; Author: Education 4u;https://www.youtube.com/watch?v=IiL_wwFIuaA;License: Standard Youtube License