Professional Documents
Culture Documents
Assignment 01 FA20
Assignment 01 FA20
Assignment 01 FA20
Islamabad Campus
Department of Computer Science
bool is_empty() the method returns true when the List C empty and false in other case
int find_common() the method returns item x which is common in List A and List B
void insert_common_descending (int a) the method inserts common element in List C in descending order
Question # 2
There are two static lists A and B containing the integer data(randomly). List A contain only even numbers in
odd range and list B contain only odd numbers in even range. Write an algorithm that create a List D that
merge elements of both lists alternatively (i.e. first place even number and then odd number).
void insert_ListD (int a) the method inserts element of List A and B in List D in alternatively
Note: Let s1 and s2 be the values return by methods size_ListA() and size_ListB() respectively, then the size
of list D is s = s1 + s2.
Question # 3 (Linked List) Dynamic List
Write an algorithm that take input integer value k where k is less than the number of nodes in given linked list.
The algorithm than swap kth node from beginning with kth node from end in a given Linked List.
For example, the given list is:
7 4 9 3 11 8 N
7 11 9 3 4 8 N
7 11 9 3 4 8
Sum1 = 11+3+8 = 22
Sum2 = 7+9+4 = 20
Output is: