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)
- Write a function that changes the places of the first and second nodes of a linked list. I.e. the First node will become the second node, and the second node will become the first node. THE FUNCTION WILL NOT EXCHANGE DATA, IT WILL CHANGE LINKS.arrow_forwardConsider the following function that takes reference to head of a Doubly Linked List as parameter. Assume that anode of doubly linked list has previous pointer as prev and next pointer as next.void fun(struct node **head_ref){struct node *temp = NULL;struct node *current = *head_ref;while (current != NULL){temp = current->prev;current->prev = current->next;current->next = temp;current = current->prev;}if(temp != NULL )*head_ref = temp->prev;}Assume that reference of head of following doubly linked list is passed to above function 1 <--> 2 <--> 3 <--> 4 <--> 5 <-->6. What should be the modified linked list after the function call? Note: solve as soon as possiblearrow_forwardWrite a function Delete(x,L) in Pascal that deletes last occurrence of x in a singly linked list and returns the number of elements (not the elements*) before the deleted element x. MANDATORY FOR CODE TO BE IN PASCAL.arrow_forward
- C++ 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_forwardWrite a function with the signature below that returns the sum of the last k elements of a singly linked list that contains integers. int returnSumOfLastKNodes(Node* head, int k) Example: 10 -> 5->8->15->11->9->23 10 represents the head node, returnSumOfLastKNodes(Node* head, 4) will return 58.arrow_forwardIn Ocaml Write a function l3_of_3l : ’a list * ’b list * ’c list -> (’a * ’b * ’c) list = that transforms a triple of lists into lists of triples. If lengths don’t match then ignore leftover elements. examples l3_of_3l ([1;2;3] ,[1.;2.] ,[ ’ a ’; ’b ’; ’c ’; ’d ’]) ;;- : ( int * float * char ) list = [(1 , 1. , ’a ’) ; (2 , 2. ,’b ’) ]l3_of_3l ([1.;2.] ,[ ’ a ’; ’b ’; ’c ’; ’d ’] ,[1;2;3]) ;;- : ( float * char * int ) list = [(1. , ’a ’ , 1) ; (2. , ’b’ , 2) ]arrow_forward
- Suppose a node of a linked list is defined as follows in your program: typedef struct{ int data; struct Node* link; } Node; Write the definition of a function, printOdd(), which displays all the odd numbers of a linked list. What will be the time complexity of printOdd()? Express the time complexity in terms of Big-O notation.arrow_forwardWrite a function that takes a list removal(L), delete from it all the elements whose indicesare divisible by 3. And return the resulting list after removing unwanted elements.Example:>>>removal(['A', 'B', 'C', 'D', 'E'])['B', 'C','E'arrow_forwardWrite a function split n l that splits the list l and returns a pairof lists containing the first n elements of l and the rest of l, wheresplit has the type int -> ’a list -> (’a list * ’a list). For ex-ample, split 3 [1,2,3,4,5] returns the pair ([1,2,3], [4,5]) andsplit 3 [1,2,3] returns ([1,2,3], []).arrow_forward
- You are going to implement a program that creates an unsorted list by using a linked list implemented by yourself. NOT allowed to use LinkedList class or any other classes that offers list functions. It is REQUIRED to use an ItemType class and a NodeType struct to solve this. Use C++, please read instructions carefully and new solution only! The “data.txt” file has three lines of data 100, 110, 120, 130, 140, 150, 160 100, 130, 160 1@0, 2@3, 3@END You need to 1. create an empty unsorted list 2. add the numbers from the first line to list using putItem() function. Then print all the current keys to command line in one line using printAll(). 3. delete the numbers given by the second line in the list by using deleteItem() function. Then print all the current keys to command line in one line using printAll().. 4. putItem () the numbers in the third line of the data file to the corresponding location in the list. For example, 1@0 means adding number 1 at position 0 of the list. Then…arrow_forwardin c++ solve this Doubly Linked List question with use class not struct Find and Replace Write the nonmember function int replaceVal(DLList<T> &list, T f, T r) which replaces every occurrence of the value f in the list with the value r. The function should also return the total number of replacements. Example: If the list myList has [ 7, 3, 5, 7, 7, 3, 8, 3] then after calling replaceVal(myList, 7, 5); myList will contain [ 5, 3, 5, 5, 5, 3, 8, 3] The function returns 3.arrow_forwardNo need source code Write a sample function with one parameter that is a head pointer for a linked list of items. The function prints all the values of the items to console.e.g., 1 -> 2 -> 3 -> 4 -> 5arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning