120 likes | 129 Views
10 Questions on Linked Lists. 1. Write efficient code to reverse the order of the contents of a singly linked list. Give the Big-Oh notation for the algorithm. 2.
E N D
10 Questions on Linked Lists
1 • Write efficient code to reverse the order of the contents of a singly linked list. Give the Big-Oh notation for the algorithm
2 • Explain two different linked list variations (from a simply singly linked list), and list a positive and negative factor for each variation.
myHead next data myTail 3 • Crazy lists. Someone has written a class that creates CrazyLists. These are linked lists made up of singly linked nodes. But instead of making a nice sequential list, the class creates crazy linked structure. Some nodes data field point to other nodes instead of data. This leads to a branching structure that could look like this:
Notes: • all data pointers that are not shown are pointing to non-Node objects or are null. • Write a method that determines the distance (number of links) from the head node to the tail node. • the tail node could be pointing at ANY of the nodes in the structure • There will be only one path from myHead to myTail • the Crazy list will not contain cycles, circular references that create loops in the structure.
4 • The following function is supposed to return the length of a linked list. What is wrong?
5 • The following function is supposed to recursively return the length of a linked list. What is wrong?
6 • The following function is supposed to merge two linked lists. What is wrong?
7 • The following function is supposed to print a Circular linked list. What is wrong?
8 • The following function is supposed to insert a node in an ordered Circular linked list. What is wrong?
9 • The following function is supposed to delete a node in an ordered Circular linked list. What is wrong?
10 • با توجه به ليست داده شده در زير، خروجي هر يك از شبه كدهاي زير را مشخص كنيد. void what(node *p) { if (p&& p->link) { what(p->link->link); cout<<p->data; what(p->link->link); } } what(first); node *what(node *p) { if (p && p->link) return what(p->link->link); else return p; } node *q=what(first); cout<<q->data;