Ass7_2023

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

CSC1223 Practical Assignment 7 2023

Data structures and Algorithm


Objective
Practical 07 is designed to understand the concept of Linked list and linked list based implementation of normal list.

1. A Linked list is a chain of structures or records called Nodes.


a. Create a Node with two members. One to hold the data and the other points to the next Node in the
list.
struct Node{
int Data;
struct Node * Next;
};
b. Then create a list which has a header node called head.
c. Initialize the list by writing a function void initialize (list *l).
d. Write a function boolean isEmpty(list *l) to check whether the list is empty.
e. Write a function void addFirst(list *l, int x) to insert an element x at the beginning of your list.
f. Write a function void display(list *l) to display the elements of your list.
g. Now write main method and create a list. Initialize it, insert three elements to the front and display the
list.
h. Write a function void addEnd(list *l,int x) to insert an element x at the end of your list.
i. Modify main method to add three more elements at the end of the list and display the list.
j. Write a function boolean search(list *l,int x) which will search the given element is in the list or not.
k. Check whether the given element is in the list.
l. Write a function int length(list *l) to calculate list size and return the size.
m. Display the size of your current list.
n. Write another function to add an element to given location of the list called void addAt(list *l, int x,int
loc). Follow the given instruction to develop this function
 x is the value of element that need to store and loc is the location this element going to store.
 Before going to add the element, need to check the given location is valid or not.
 If the given location is equals to listsize+1 then need to call your addEnd() function.
 If the given location is equals to 1 then need to call addFirst() function.
 If not need to add to the proper location.
o. Now add several elements by giving the location using addAt() function to test the each cases.
p. Display the list.

© DCS@RUH 24/07/2023 1

You might also like