0% found this document useful (0 votes)
104 views

KIE1008 (Theory Tutorial) Session 2016/2017 (Semester 2)

This document discusses linked lists and provides examples and problems related to linked lists. It begins with an example linked list containing several nodes with data values. It then provides 7 problems related to manipulating and traversing linked lists using pointers. The problems cover tasks like printing out node values, checking relationships between nodes, performing insertions and deletions, and completing tables describing node relationships.

Uploaded by

Mazen Jamal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views

KIE1008 (Theory Tutorial) Session 2016/2017 (Semester 2)

This document discusses linked lists and provides examples and problems related to linked lists. It begins with an example linked list containing several nodes with data values. It then provides 7 problems related to manipulating and traversing linked lists using pointers. The problems cover tasks like printing out node values, checking relationships between nodes, performing insertions and deletions, and completing tables describing node relationships.

Uploaded by

Mazen Jamal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

KIE1008 (Theory Tutorial) Session 2016/2017 (Semester 2)

Tutorial 3: Linked-Lists

list 18 32 23 16 43 87 25 44

A B

Assume list, A, B, p and s are pointers of type nodeType.

1. What is the output of the following statements:


a. cout << list->info
b. cout << A->info
c. cout << B->link->info
d. cout << list->link->link->link->info
2. What is the value of the following relational expressions (true of false)?
a. list->info >=18
b. list->link == A
c. A->link->info == 16
d. B->link == NULL
e. list->info == 18
3. Is the following statement valid? It no, why?
a. A=B;
b. list->link = A->link;
c. list->link->info = 45;
d. *list = B;
e. *A = *B;
f. B = A->link->info;
g. A->info = B->info;
h. list = B->link->link;
i. B = B->link->link->link;
4. Write C++ statements to do the following (declare additional variables if needed).
a. Make A point to the node containing info 23.
b. Make list point to the node containing 16.
c. Make B point to the last node of the list.
d. Make list point to an empty list.
e. Set the value of the node containing 25 to 35.
f. Create and insert the node with info 10 after the node pointed to by A.
g. Delete the node with info 23, and deallocate the memory occupied by this node.
5. What is the output of the code?
p = list;
while (p!=null) {
cout << p->info << “ “;
p = p->link;
}
cout << endl;
KIE1008 (Theory Tutorial) Session 2016/2017 (Semester 2)

6. Consider the following statement, what is the output? (assume print() will show the info
of the list)
list.insertFirst(15);
list.insertLast(28);
list.insertFirst(30);
list.insertFirst(2);
list.insertLast(45);
list.insertFirst(38);
list.insertLast(25);
list.deleteNode(30);
list.insertFirst(18);
list.deleteNode(28);
list.deleteNode(12);
list.print();

7. Show the output.


a. list = new nodeType;
list->info = 10;
ptr = new nodeType;
ptr->info = 13;
ptr->link = NULL;
list->link = ptr;
ptr = new nodeType;
ptr->info = 18;
ptr->link = list->link;
list->link = ptr;
cout << list->info << “ “ << ptr->info << “ “ ;
ptr=ptr->link;
cout << ptr->info << “ “ << endl;

b. list = new nodeType;


list->info = 20;
ptr = new nodeType;
ptr->info = 28;
ptr->link = NULL;
list->link = ptr;
ptr = new nodeType;
ptr->info = 30;
ptr->link = list;
list = ptr;
ptr = new nodeType;
ptr->info = 42;
ptr->link = list->link;
list->link = ptr;
ptr = list;
while(ptr!=NULL) {
cout << ptr->info << endl;
ptr=ptr->link;
}
KIE1008 (Theory Tutorial) Session 2016/2017 (Semester 2)

8. Given the memory allocation as shown in the figure for a descendingly-ordered linked-list,
complete the tables with the appropriate values.

Address Value
0x10 20
0x30 18
0x50 25
0x60 56
0x80 12
(head) 0xfc X
(tail) 0xff Y

Non- Circular Non- Circular


Circular Singly LL Circular Doubly
Singly LL Doubly LL LL
head
head->info
head->next
head->next->info
head->next->next
head->next->next->info
head->next->next->next
head->next->next->next ->info
head->next->next->next->next
head->next->next->next ->next ->info
head->next->next->next->next->next
head->next->next->next ->next->next ->info
head->next->next->next->next->next->next
tail
tail->prev
tail->prev->info
tail->prev ->prev
tail->prev ->prev->info
tail->prev ->prev ->prev
tail->prev ->prev ->prev->info
tail->prev ->prev ->prev ->prev
tail->prev ->prev ->prev ->prev->info
tail->prev ->prev ->prev ->prev ->prev
tail->prev ->prev ->prev ->prev ->prev->info
tail->prev ->prev ->prev ->prev ->prev ->prev
tail->prev ->prev ->prev ->prev ->prev ->prev->info
---END---

You might also like