CSE220 Lab 2 - Linked List
CSE220 Lab 2 - Linked List
Linked List
Task 1:
i) Create a Node class which will hold two fields i.e an integer element and a reference
to the next Node.
ii) Create a Linked list Abstract Data Type (ADT)named MyList.The elements in the
list are Nodes consisting of an integer type key (all keys are unique) and a reference to
the next node.
[You are not allowed to use any global variable other than head]
1. Constructor:
a. MyList (int [] a) or def __init__ (self, a) (5)
Precondition: None.
Postcondition: Outputs the keys of the elements of the order list. If the list is
empty, outputs “Empty list”.
Pre-condition: None.
Post-condition: Returns true if a list is empty. Otherwise, returns false.
6. void insert (int newElement, int index) or def insert(self, newElement, index) (4)
1. Write a function to find out the even numbers that are present in the list and output
another list with those numbers. (3)
2. Write a function to find out if the element is in the list or not. (3)
3. Write a function to reverse the list. [You are not allowed to create any other list] (3)
4. Write a function to sort the list. [You are not allowed to create any other list] (3)
5. Write a function that prints the sum of the values in the list. (4)
Sample Input Sample Output
6. Write a function that rotates the elements of the list k times. [You are not allowed to
create any other list]. (4)