2
Dep. Of Computer Systems/ Second Class Data Structures Exercises Write in C++ programming language a complete program for Each of the following exercises: A. Create a linked-list of eight (8) nodes by adding from the end of the linked-list, and then print the values of data fields of all nodes in it. B. Create a linked-list of five (5) nodes by adding from the beginning of the linked-list, print the values of data fields of all nodes in it, and then insert a new node between the 3 rd and 4 th nodes, then re-print the linked list. C. Create a linked-list of seven (7) nodes by adding from the beginning of the linked-list, print the values of data fields of all nodes in it, and then delete the latest node, then re-print the linked list. D. Create a linked-list of ten (10) nodes by adding from the beginning of the linked-list, print the values of data fields of all nodes in it, and then delete the node that its value = 20 (if it exist) , then re-print the linked list. (each node must have a unique value) E. Create a linked-list of seven (7) nodes by adding from the beginning of the linked-list, print the values of data fields of all nodes in it, and then delete the 4 th node, then re- print the linked list. F. Create a linked-list of five (5) nodes by adding from the beginning of the linked-list, print the values of data fields of all nodes in it, and then change the value of data field for all nodes by multiply it by (3), then re-print the linked list.

Data Structures Exercises- Liked List

Embed Size (px)

Citation preview

Dep. Of Computer Systems/ Second Class Data Structures Exercises

Write in C++ programming language a complete program for Each of the following exercises:A. Create a linked-list of eight (8) nodes by adding from the end of the linked-list, and then print the values of data fields of all nodes in it. B. Create a linked-list of five (5) nodes by adding from the beginning of the linked-list, print the values of data fields of all nodes in it, and then insert a new node between the 3rd and 4th nodes, then re-print the linked list.C. Create a linked-list of seven (7) nodes by adding from the beginning of the linked-list, print the values of data fields of all nodes in it, and then delete the latest node, then re-print the linked list.D. Create a linked-list of ten (10) nodes by adding from the beginning of the linked-list, print the values of data fields of all nodes in it, and then delete the node that its value = 20 (if it exist) , then re-print the linked list. (each node must have a unique value)E. Create a linked-list of seven (7) nodes by adding from the beginning of the linked-list, print the values of data fields of all nodes in it, and then delete the 4th node, then re-print the linked list.F. Create a linked-list of five (5) nodes by adding from the beginning of the linked-list, print the values of data fields of all nodes in it, and then change the value of data field for all nodes by multiply it by (3), then re-print the linked list.

Notice: use the following identifications in each of the above programs: struct listNode{ int data; listNode *next; };typedef listNode *ptr;

G. Create a linked-list of (n) nodes by adding from the beginning of the linked-list, each node must have the following information: (Name and Age) of each member your group, and then print the values of all information fields of all nodes in it.