Write a function called mergeLists that takes two call-by-reference arguments that are pointer variables that point to the heads of linked lists of values of type int. The two linked lists are assumed to be sorted so that the number at the head is the smallest number, the number in the next node is the next smallest, and so forth. The function returns a pointer to the head of a new linked list that contains all of the nodes in the original two lists. The nodes in this longer list are also sorted from smallest to largest values. Note that your function will neither create nor destroy any nodes. When the function call ends, the two pointer variable arguments should have the value NULL.
Trending nowThis is a popular solution!
Chapter 13 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Computer Science: An Overview (12th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Modern Database Management (12th Edition)
- Implement a function void printAll(void) to print all the items of the list.arrow_forwardDo the whole code in C++ and please kindly share the whole code.arrow_forwardWrite a functionLi stNode *removeFirst( ListNode *ptr)that is passed a linked list as parameter and returns the tai l of the list: That is, itremoves the first node and returns what is left. The function should deallocate thestorage of the removed node. The function returns null ptr if the list passed to itis empty.arrow_forward
- C++arrow_forwardC++ ONLY Add the following functions to the linked list. int getSize() -> This function will return the number of elements in the linked-list. This function should work in O(1). For this keep track of a size variable and update it when we insert a new value in the linked-list. int getValue(index) -> This function will return the value present in the input index. If the index is greater or equal to the size of the linked-list return -1. void printReverse() -> This function will print the linked list in reverse order. You don’t need to reverse the linked list. Just need to print it in reverse order. You need to do this recursively. You cannot just take the elements in an array or vector and then print them in reverse order. void swapFirst() -> This function will swap the first two nodes in the linked list. If the linked-list contains less than 2 elements then just do nothing and return. To check your code add the following code in your main function. LinkedList l;…arrow_forwardWrite a function void printSecond(ListNode *ptr) that prints the value stored in the second node of a list passed to it as parameter. The function should print an error message and terminate the program if the list passed to it has less than two nodes.arrow_forward
- Write a function that accepts two lists as it's only arguments. The function should return a new list containing all the elements of the two list arguments. For example, if the function was passed the lists [1, 2, 3] and [4, 5, 6], it would return a new list containing [1, 2, 3, 4, 5, 6]arrow_forwardin c++arrow_forwardC++ program for the following please: Create a generic function print(ls, n) that prints to standardoutput the first n elements of list ls. The elements are printed on separatelines. If ls has less than n elements, then the entire list is printedarrow_forward
- True/False Select true or false for the statements below. Explain your answers if you like to receive partial credit. 3) Which of the following is true about the insertBeforeCurrent function for a CircularLinked List (CLL) like you did in programming exercise 1?a. If the CLL is empty, you need to create the new node, set it to current, andhave its next pointer refer to itselfb. The worst case performance of the function is O(n)c. If you insert a new element with the same data value as the current node, theperformance improves to O(log n)arrow_forwardComplete question bcoding:-.arrow_forwardWrite a function that takes in n ADT Lists in an array. The function is going to be called Intersection, and it will return a new list with the elements common to all the n lists. Determine the time complexityarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning