Struct Node Represents A Node In Linkedlists Functions Createlinkedlist Receive The Size Of A Linked List 0 1 (53.88 KiB) Viewed 30 times
Struct Node Represents A Node In Linkedlists Functions Createlinkedlist Receive The Size Of A Linked List 0 2 (5.59 KiB) Viewed 30 times
Struct Node Represents A Node In Linkedlists Functions Createlinkedlist Receive The Size Of A Linked List 0 3 (34.15 KiB) Viewed 30 times
- struct node: represents a node in linkedlists - functions createLinkedList: + Receive the size of a linked list (>0) + create a linked list with value from standard input (stdin) a new node is add to the END of the linked list + Return a pointer which points to the first node of the linked list. - Function mergeList: + receive 2 head1, head2 pointers of 2 linked lists + Function mergeList will change the 1st linked list so that the 2nd linked list will be concatenated to the end of the 1st linked list - function main reads the linked list's size, calls function createLinked List to initialize the linked list, then calls function print to print the linked list. Complete the functions mergeList Input: All the inputs from standard input (stdin) with value in (0; 5000) Output: Satisfy the requirements Write a program where:
For example: Test Input 1 Result 5 1 1 3 5 7 9 3 2 5 12 7 9 1 2
1 #include <iostream> 2 using namespace std; 3 struct node 4 + { 5 6 7 }; 8 node *createLinked List(int n); // The implementation is provided implicitly 9 void mergeList(node* head1, node* head2) 10 - { 11 15 16 ▾ 17 18 12} 13 void print (node *head) 14-{ int data; node *next; 22 - { 23 24 25 26 27 28 29 30 31 // TODO 32 } 33 while (head != nullptr) { 19 20 } 21 int main() } cout << head->data << endl; head->next; head = int n = 0; cin >>n; node *head = createLinkedList(n); int m; cin>>m; node *head1 = createLinkedList (m); mergeList (head, head1); print (head); return 0;
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!