EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Question
Chapter 3, Problem 1E
Program Plan Intro
Circular doubly linked list:
- In a circular doubly linked list, the last node’s “Next” pointer points to first node and “Prev” pointer of first node points to last node making the list circular from both of the directions.
- The “Next” of last link points to first link of list
- The “Prev” of first link points to last of list.
- A circular doubly linked list is shown below:
Expert Solution
Explanation of Solution
Modification of linked list:
Refer figure 3.29 from chapter 3 for the given circular doubly linked list.
Assignment 1
- In the given list list->next denotes first element of list whose value is 1.
- In the given list list->next->next denotes second element of list whose value is 2.
- In the given list list->next->next->next denotes the third element of list whose value is 3
- In the given list list->prev denotes the last element of list whose value is 5, as the list is circular doubly linked list.
- Hence, assignment 1 would make the “Next” of node 3 to point to node 5. Hence, the result is “node 3 to node 5”.
Explanation of Solution
Assignment 2
- In the given list list->prev denotes first element of list whose value is 1.
- In the given list list->prev->prev denotes last element of list whose value is 5.
- In the given list list->prev->prev->prev denotes the fourth element of list whose value is 4
- In the given list list->next denotes first element of list whose value is 1
- In the given list list->next->next denotes second element of list whose value is 2
- In the given list list->next->next->next denotes the third element of list whose value is 3
- In the given list list->next->next->next->prev denotes the “Prev” of fourth element of list
- Hence, assignment 2 would make node 4 point to node 4 itself. Hence, the result is “node 4 to node 4”.
Explanation of Solution
Assignment 3
- In the given list list->next denotes first element of list whose value is 1.
- In the given list list->next->next denotes second element of list whose value is 2.
- In the given list list->next->next->next denotes the third element of list whose value is 3
- In the given list list->next->next->next->prev denotes the previous of fourth element of list
- In the given list list->prev denotes the last element of list whose value is 5, as list is circular linked list.
- In the given list list->prev->prev denotes the fourth element of list whose value is 4.
- In the given list list->prev->prev->prev denotes the previous of fourth element of list
- Hence, assignment 3 would denote same thing and list remains the same. Hence, the result is “No change”.
Explanation of Solution
Assignment 4
- In the given list list->next denotes the first element of list whose value is 1.
- In the given list list->next->next denotes the third element of list whose value is 3.
- Hence, assignment 4 would make the node 1 point to node 3. Hence, the result is “node 1 to node 3”.
Explanation of Solution
Assignment 5
- In the given list list->next denotes the first element of list whose value is 1.
- In the given list list->next->next denotes the second element of list whose value is 2.
- In the given list list->next->next->next denotes the “next” of second element of list whose value is 2.
- In the given list list->next denotes the second element of list whose value is 2.
- In the given list list->next ->prev->next denotes the first element of list whose value is 1.
- Hence, assignment 5 would make the “next” node 2 point to node 1. Hence, the result is “node 2 to node 1”.
Want to see more full solutions like this?
Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Q4
Suppose, alist is a 2-dimensional list that is defined as follows.
alist = [ [1], [2,3], [5,6,7] ]
Which is the best option to access the last element of the last element of this list (i.e., 7)?
Question 4 options:
alist[ len(alist) - 1 ][len(alist[len(alist) - 1]) - 1]
alist[ len(alist) - 1 ][len(alist[len(alist) - 1])]
alist[3][3]
alist[ len(alist) - 1 ][1]
Computer Science
Describe a situation where you may wish to create a link list of ITERATORS. Is it possible to create a link list of various types of iterators? For example a list with list iterators, map iterators, and set iterators?
Consider a Single Linked List (SLL) of nodes, where ‘node’ is a type with two fields: integer data and the node type reference ‘next’ that refers to the next node in the list. For each part given below consider the SLL and the code given in the second column. Following the execution of the code, show the resulting list (in the answer box, for each part, use the arrow key to draw the list as: head-----> ? -------> ? --------> ?).
List and Java Code
a
head ⟶ 1⟶ 2⟶ 3⟶ 4⟶ null
node ptr=head;
node newnode = new node(0); // data=0
head = newnode;
newnode.next=ptr;
b
head ⟶ 1⟶ 2⟶ 3⟶ 4⟶ null
node ptr=head;
node newnode = new node(6); // data=6
while(ptr.next!=null) {
ptr=ptr.next;
}
ptr.next=newode;
c
head ⟶ 1⟶ 2⟶ 3⟶ 4⟶ null
node ptr=head;
ptr=ptr.next;
head=ptr;
Chapter 3 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
Ch. 3 - Prob. 1ECh. 3 - Prob. 2ECh. 3 - Prob. 3ECh. 3 - Prob. 4ECh. 3 - Prob. 5ECh. 3 - Prob. 6ECh. 3 - Prob. 7ECh. 3 - Prob. 8ECh. 3 - Prob. 9ECh. 3 - Prob. 10E
Ch. 3 - Prob. 11ECh. 3 - Prob. 12ECh. 3 - Prob. 13ECh. 3 - Prob. 14ECh. 3 - Prob. 15ECh. 3 - Prob. 16ECh. 3 - Prob. 17ECh. 3 - Prob. 18ECh. 3 - Prob. 19ECh. 3 - Prob. 20ECh. 3 - Prob. 21ECh. 3 - Prob. 22ECh. 3 - Prob. 23ECh. 3 - Prob. 24ECh. 3 - Prob. 25ECh. 3 - Prob. 1PACh. 3 - Prob. 2PACh. 3 - Prob. 3PACh. 3 - Prob. 5PACh. 3 - Prob. 7PA
Knowledge Booster
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
- Write a program which will concatenate two single linked lists. The structure is defined below. Assume that head1 contains the starting address of the first list and head2 contains the starting address of the second list. You need to join them together so that all the students’ roll no and names of both the lists will be displayed together with the help of head1 pointer. struct link { int rollno; char name[20]; struct link *next; }; typedef struct link node; node *head1=NULL, *head2=NULL; //global declarationarrow_forwardAssume a linked list contains following integers: 4, 2, 6, 5, 8, 3, 15 and the pointer head is pointing to the first node of the list. What will be the value of variable a after the following statements are executed: Node<int> *curNode=head; int a; curNode=curNode->getNext(); head->setNext(curNode); head=head->getNext(); a=head->getItem(); A.2 B.4 C.6 D.15arrow_forwardFor this assignment, you need to implement link-based List and derivative ADTs in Java. To complete this, you will need the following: A LinkNode structure or class which will have two attributes - a data attribute and a pointer attribute to the next node. The data attribute of the LinkNode should be the Money class of Lab 1. A Singly Linked List class which will be composed of three attributes - a count attribute, a LinkedNode pointer/reference attribute pointing to the start of the list and a LinkedNode pointer/reference attribute pointing to the end of the list. Since this is a class, make sure all these attributes are private. The attribute names for the Node and Linked List are the words in bold in #1 and #2. For the Linked List, implement the most common linked-list behaviors as explained in class - getters/setters/constructors/destructors for the attributes of the class, (a) create new list, (b) add data, (c) delete data, (d) find data, (e) count of data items in the…arrow_forward
- TRUE or FALSE? Answer the following question and state the reason why: The delete operation only involves the removing of the node from the list without breaking the links created by the next node. You need an array to represent each node in a linked list. STL lists are also efficient at adding elements at their back because they have a built-in pointer to the last element in the list. A circular linked list has 2 node pointers. cout<<list.back()<<endl; = The back member function returns a reference to the last element in the list. In a Dynamic Stack, the pointer top stays at the head after a push operation. During a Pop operation in Static Stack, the elements are being moved one step up. In a dynamic implementation of stack, the pointer top has an initial value of null. In a dynamic stack, the node that was popped is deleted. In a dynamic stack, the pointer top stays at the head after push operation. STL function top returns a reference to element at the top of the…arrow_forwardAssume a linked list contains following integers: 7, 2, x, 5, 8, x, 15 and the pointer head is pointing to the first node of the list. What will be the value of variable a after the following statements are executed: Node<int> *curNode=head; curNode=curNode->getNext(); curNode=curNode->getNext(); int a; a=curNode->getItem(); 1. x 2. 2 3. 7 4. x+9arrow_forwardWrite 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_forward
- Assume a linked list contains following integers: 5, 2, 4, 6, 8, 3, 15 and the pointer head is pointing to the first node of the list. What will be the value of variable a after the following statements are executed: Node<int> *curNode=head; curNode=curNode->getNext(); curNode=curNode->getNext(); int a=curNode->getItem()<<endl; Group of answer choices A.4 B.2 C.5 D.6arrow_forwardAssume a linked list contains following integers: 5, 2, 4, 6, 8, 3, 15 and the pointer head is pointing to the first node of the list. What will be the value of variable a after the following statements are executed: Node<int> *curNode=head; int a=0; while(curNode!=NULL){ a+=curNode->getItem(); curNode=curNode->getNext(); if(curNode!=NULL) curNode=curNode->getNext(); } A.32 B.43 C.19 D.18arrow_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
- A linked list is said to contain a cycle if any node is visited more than once while traversing the list. Given a pointer to the head of a linked list, determine if it contains a cycle. If it does, return . Otherwise, return . Example refers to the list of nodes The numbers shown are the node numbers, not their data values. There is no cycle in this list so return . refers to the list of nodes There is a cycle where node 3 points back to node 1, so return . Function Description Complete the has_cycle function in the editor below. It has the following parameter: SinglyLinkedListNode pointer head: a reference to the head of the list Returns int: if there is a cycle or if there is not Note: If the list is empty, will be null. Input Format The code stub reads from stdin and passes the appropriate argument to your function. The custom test cases format will not be described for this question due to its complexity. Expand the section for the main function and review the…arrow_forwardAssume a linked list contains following integers: 7, 2, 9, 5, 8, 3, 15 and the pointer head is pointing to the first node of the list. What will be the value of variable a after the following statements are executed: Node<int> *curNode=head; int a; while(curNode->getNext()!=NULL){ { curNode=curNode->getNext(); } a=curNode->getItem(); A. 15 B. 7 C. 49 D. 3arrow_forwardAssume a linked list contains following integers: 2, 2, 4, 5, 8, 3, 15 and the pointer head is pointing to the first node of the list. What will be the value of variable a after the following statements are executed: Node<int> *curNode; curNode=new Node<int>(10,head); head=curNode; int a; while(curNode!=NULL){ a+=curNode->getItem(); curNode=curNode->getNext(); } A.49 B.39 C.7 D.15arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
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