Assignment 5 + Homework - Linked Lists

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Linked List - Homework

Implement following functions in class Linked List


i. Implement Stack using Singly Linked List
ii. Implement Queue using Singly Linked List
iii. void Insert(int d)
This will insert an element in Linked List, duplicate data is allowed and the Linked List should
remain sorted after insertion.
iv. bool Delete(int d)
If there exists a node with data = d, this function will delete this node and will return true,
otherwise it will return false. If there are multiple occurrences of data d in the linked list
then it should delete only first node with data d.
v. Destructor
vi. Node* Merge (Node* head1, Node* head2)
This function merges two linked lists in linear time. Function should not create any new
node, it will just update the links of existing nodes.

Sample Run:
Before Function Call:
Linked List 1: 10, 20, 30, 40, 50
Linked List 2: 5, 15, 25, 35
Merged List:

After Function Call:


Linked List 1:
Linked List 2:
Merged List: 5, 10, 15, 20, 25, 30, 35, 40, 50

vii. void Compress(Node* head)


This function takes head of a linked list and removes duplicate nodes from the list. There
shouldn’t be any memory leakage after compression.
Sample Run:

Linked List Before Function Call: 1, 2, 3, 4, 4, 4, 5, 5, 6, 7, 7, 7, 7, 7, 10


Linked List after Function Call: 1, 2, 3, 4, 5, 6, 7, 10

viii.
1)

Write a function (both iterative and recursive versions) that takes a linked list and
prints it in reverse order. For example:

Input Linked List:


1->2->3->4->5
Function Output on console:
5, 4, 3, 2, 1

Write a recursive function that reverses a linked list. For example

Linked List Before function call: (Head is 1)


1->2->3->4->5
Linked List After function call: (Now head is 5)
1<-2<-3<-4<-5

Assignment 5 - Linked List

Make an application that performs following tasks:


1- Display Contact List sorted by Name
2- Insert new Contact
3- Search Contact by Name
4- Delete a Contact
5- Update Name or Phone Number of a Contact.

Properly show all the functionalities in main function. Do not ask ANY input from user. Evaluator should
be able to just run your program and it should clearly print and show all the functionalities (listed above)
on console. Submit your txt file as well.
Save following List of Contacts in a text file then implement above application:

21-Aug 18L-2096 Jawad Farooq


21-Aug 18L-1810 Faraz Javed
21-Aug 18L-2098 Shahzeb Shahzad
21-Aug 18L-2120 Wajahat Ali
31-Aug 19L-1843 Hamza Hussain
21-Aug 19L-1826 Iqra Ijaz
21-Aug 19L-1851 Fahad Younas
21-Aug 19L-1872 Adil Cheema
21-Aug 19L-2401 Zain Ali
21-Aug 19L-2404 Ameer Hamza
21-Aug 19L-2438 Aziz Ur
21-Aug 19L-2445 Gull E
2-Sep 19L-2453 Umar Bashir
21-Aug 19L-2458 Amna Waheed
21-Aug 19L-2460 Shahroze Ali
21-Aug 19L-2473 Akash Sohail
21-Aug 19L-2476 Anam Ghaffar
31-Aug 20L-2251 Muhammad Bilal
31-Aug 20L-2252 Hamza Khan
31-Aug 20L-2255 Muzammil Ahmad
31-Aug 20L-2257 Hamza Hamid
31-Aug 20L-2260 Shahrukh Yasin
31-Aug 20L-2263 Hassan Abbas
31-Aug 20L-2265 Samia Akhter
31-Aug 20L-2266 Hafiz Hamza
31-Aug 20L-2267 Asad Ullah
7-Sep 20L-2268 Hamza Ayub
31-Aug 20L-2269 Muhammad Umer
1-Sep 20L-2271 Roha Arif
1-Sep 20L-2273 Sameera Kanwal
31-Aug 20L-2274 Ayesha Abouzar
2-Sep 20L-2275 Mustajab Noor
1-Sep 20L-2277 Zaeem Ahmed
31-Aug 20L-2279 Maryam Rehman
31-Aug 20L-2281 Daniyal Yahya
11-Sep 20L-2285 Haiqa Saman
31-Aug 20L-2288 Haroon Azhar
31-Aug 20L-2289 Subhan Yousaf
31-Aug 20L-2293 Sallahuddin Khan
31-Aug 20L-2295 Ayyaz Sheikh
31-Aug 20L-2296 Nabeel Mushtaq
31-Aug 20L-2298 Marwa Khan
31-Aug 20L-2299 Muhammad Nabeel
10-Sep 20L-2306 Sana Bari
31-Aug 20L-2308 Ifrah Dar
1-Sep 20L-2315 Khawaja Waleed
31-Aug 20L-2320 Muhammad Anwar
2-Sep 20L-2321 Khulda Zubair
21-Sep 20L-2323 Ruhma Aziz
31-Aug 20L-2333 Usman Nasir
1-Sep 20L-2334 Iram Shahzadi
31-Aug 20L-2336 Asama Ikram
31-Aug 20L-2340 Kinza Sial
31-Aug 20L-2347 Fareeha Ashfaq
31-Aug 20L-2360 Rimsha Gul
31-Aug 20L-2367 Muhammad Fahad
21-Sep 20L-2368 Ahmad Shahid
10-Sep 20L-2373 Abdul Haseeb
1-Sep 20L-2381 Ubaid Ur
7-Sep 20L-2384 Talha Ali
11-Sep 20L-2385 Tayyaba Suleman
19-Sep 20L-2386 Tahreem

You might also like