Concept explainers
Linked list:
Linked list is a linear and dynamic data structure which is used to organize data; it contains sequence of elements which are connected together in memory to form a chain. The every element of linked list is called as a node.
List head:
List head is a pointer used to point the first node in the linked list and it is also called as “head pointer”; if the “head pointer” points to a “NULL” value, then it is considered that the “list is empty”.
Graphical representation of linked list:
The graphical representation of a linked list is as follows:
Traversing the list:
Traversing the linked list is the process of visiting the list until reaching the last node. It is one of the operations in the list, which is used to visit each node exactly once in order to access the data stored in the list.
Steps to traversing a list:
The following steps are used to perform the traversing operation in a list.
Step 1: Move to the list head (first node).
Step 2: Retrieve the data from the head node and perform the necessary operation.
Step 3: After performing operation, move the pointer to next node and perform the operation until the end of the node.
Step 4: Perform all the above travelling nodes as a visited node.
Usage of traversing the list:
Print the elements.
- Traversing the list used to display all elements from the list.
Count the elements.
- Traversing the list used to count the number of elements available in the list.
Search the element.
- Traversing the list used to search a particular value in the list.
Want to see the full answer?
Check out a sample textbook solutionChapter 17 Solutions
MyLab Programming with Pearson eText -- Standalone Access Card -- for Starting Out With C++: Early Objects (My Programming Lab)
- The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of the list after the function completes execution? struct node { int value; struct node *next; }; void rearrange(struct node *list) { struct node *p, * q; int temp; if ((!list) || !list->next) return; p = list; q = list->next; while(q) { temp = p->value; p->value = q->value; q->value = temp; p = q->next; q = p?p->next:0; } } a) 1, 2, 3, 4, 5, 6, 7b) 2, 1, 4, 3, 6, 5, 7c) 1, 3, 2, 5, 4, 7, 6d) 2, 3, 4, 5, 6, 7, 1arrow_forwardWrite a function REMOVE-NUM that takes a list and returns a list consisting of the original list with all numeric atoms removed. Examples: (REMOVE-NUM '(2 A 6 B 1 C 7 D)) returns the list (A B C D) (REMOVE-NUM '(3 A 4 B (1 E) 7 D)) returns the list (A B (E) D)arrow_forwardGiven two lists(List1, List2) of INTs create a third list such that should contain only odd numbers from the first list and even numbers from the second list def mergeList(listOne, listTwo): thirdList = [] #complete the functionarrow_forward
- struct node{int num;node *next, *before;};start 18 27 36 45 54 63 The above-linked list is made of nodes of the type struct ex. Your task is now to Write a complete function code to a. Find the sum of all the values of the node in the linked list. b. Print the values in the linked list in reverse order. Use a temporary pointer temp for a and b. i dont need a full code just the list partarrow_forwardCreate a function that takes the first Node in a linked list as an input, reverses the list (destructively), and then returns the original Node.arrow_forwardWrite a function that changes the places of the first and last nodes of a linked list. I.e. First node will become last node, and the last node will become first node. Others nodes will not be affected.THE FUNCTION WILL NOT EXCHANGE DATA, IT WILL CHANGE LINKS.arrow_forward
- C Language In a linear linked list, write a function named changeFirstAndLast that swaps the node at the end of the list and the node at the beginning of the list. The function will take a list as a parameter and return the updated list.arrow_forwardİn C language A singly linear list stores integer values in each node and has multiple nodes. Write a function using given prototype below. This function cuts the first node of the list and adds it to the end as last node. It takes beginning address of the list as a parameter and returns the updated list.struct node* cutheadaddlast(struct node* head);struct node { int number; struct node * next; };arrow_forwardWrite a function get_list_avg() that expects a parameter main_list (a list of lists) and returns a new list that contains the average of each sub-list in main_list. The function should return an empty list if the main_list is empty. this is my answer: def get_list_avg(main_list ): new_list = [] for sublist in main_list: avg = sum(sublist) / len(sublist) new_list.append(avg) return new_list main_list = input() print(get_list_avg(main_list))arrow_forward
- write a C++ complete code of the Linked-ListLinked List must contain the following functions:a. Insertion( )b. Display( )c. Append( )d. Delete( )e. Update( )arrow_forwardWrite C code that implements a soccer team as a linked list. 1. Each node in the linkedlist should be a member of the team and should contain the following information: What position they play whether they are the captain or not Their pay 2. Write a function that adds a new members to this linkedlist at the end of the list.arrow_forwardC Language In a linear linked list, write a function that deletes the element in the middle of the list (free this memory location) (if the list has 100 or 101 elements, it will delete the 50th element). The function will take a list as a parameter and return the updated list.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning