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
Data structure and algorithms. DYNAMIC DATA STRUCTURE LINKED LIST. PURPOSE OF WORK : Consolidation of knowledge on the theoretical foundations of presentation of data in the form of links, classification of lists, learning to solve problems using the LIST standard template library in C++. Task : Write a program to process a linked list from the standard template library. Perform an individual task as a separate function. Implementation of automatic filling and display functions with random data in the program. The task is : The list is given. Create a function to calculate the arithmetic mean value of the elements of the list equal to the Fibonacci number.
PYTHON CODE - WRITE PYTHON FUNCTION
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)
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