100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Summary

Summary All Lab work

Rating
-
Sold
-
Pages
4
Uploaded on
14-01-2021
Written in
2020/2021

Summary of 4 pages for the course Data Structures at Comsats Institute Of Information And Technology (All Lab work)

Institution
Course

Content preview

1. Singly Linked Lists
The objective of this lab session is to acquire skills in working with singly linked lists. The task is to first
implement the following operations:

1) Create an empty linked list; // do so in the constructor.

2) bool IsEmpty(); // checks whether the list is empty or not. Returns true if empty and false otherwise.

3) InsertAtFront(value); // takes input from a user and inserts it at front of the list

4) Void PrintList();

5) InsertSorted(value); //If we want to maintain a sorted list, we should implement this function

6) Search(value); This function shall search value in a list. If found, we will need to store two addresses:

a. Address of the node in which the searched value is found in a pointer variable named Loc_;
we will store NULL in Loc_ in case value is not found.

b. Address of the node which is logical predecessor of value in a list.

i. The Search() provides functionality for other operations such as insertion in a sorted
list, deleting a value, modifying a value, printing it etc.

7) Delete(value); // searches value and then deletes it if found.

8) DestroyList(); // Distroys all nodes of the list leaving the list in empty state.

Declare Node Class: The data structure that will hold the elements of the list is called Node.
Declare it as follows:
class ListNode{
public:
int data;
ListNode *next;

};

Declare class Linked List:
Now, declare your main class LinkedList. Inside
this class, you shall define all key functions to implement all operations
of a linked list.

class LinkedList{
public:
ListNode *start; // special variable which stores address of head
node.
ListNode *PredLoc_; //to be used by Search(value) method to store
address of logical predecessor of value in a list.
ListNode *Loc_; //to be used by Search(value) method to store address
of the node containing the searched value in a list. If it is not found it
contains NULL.
}

1) Creating a LinkedList
In order to create an empty list, assign NULL value to start pointer
variable.
LinkedList(){
start=NULL;

Written for

Institution
Course

Document information

Uploaded on
January 14, 2021
Number of pages
4
Written in
2020/2021
Type
Summary

Subjects

$7.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
youtubecanvas

Get to know the seller

Seller avatar
youtubecanvas COMSATS Institute Of Information Technology
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
5 year
Number of followers
0
Documents
18
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions