0% found this document useful (0 votes)
126 views36 pages

Paper 2 ADT

Uploaded by

sardarawais.ak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views36 pages

Paper 2 ADT

Uploaded by

sardarawais.ak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

PAPER 2

9618

ABSTRACT DATATYPE
Abstract Datatype

An Abstract Datatype is a collection of data


and set of operations on that data

Stack Queue Linked List


PAPER 2
9618

STACK
Stacks

A list containing several items operating on


the last in first out principle (LIFO).
Items can be added to the stack (PUSH) and
removed from the stack (POP).
The first item added to the stack is the last
item removed from the stack
Push("Taha")
Push("Ali")
Push("Amjad")
Push("Bano")
Pop()
Pop()
Push("Qasim")
Question

Each Character from the word "Papersdock"


is added into the stack one by one and when
all the characters were popped out the string
looked different. ("kcodsrepaP")
Answer

The Stack follows the principle of Last In First Out


so the first item added in the stack is remved at
the end so thats why the order is reversed
PAPER 2
9618

QUEUE
Queue
A list containing several items operating on
the first in first out principle (FIFO).
The first item added is the first item remove
from the queue
In queue the data is added from the rear end
by using the EndPointer and removed from
the front by using the StartPointer
Enqueue("Taha")
Enqueue("Ali")
Enqueue("Amjad")
Enqueue("Bano")
Dequeue()
Dequeue()
Enqueue("Qasim")
Linear Vs Circular

The condition for a linear queue being


full is that rearpointer or the endpointer
should point towards upperbound or
the max index
Dequeue()
Dequeue()
According to the condition of queue
being full is still true so if you want
to enqueue a value it will still print
"The Queue Is Full"
Circular Queue
PAPER 2
9618

LINKED LIST
Ordered Linked List And Unordered Linked List

A linked list is a data structure used to store a collection of


items where each item is linked to the next one using pointers.
There are two types of linked lists: ordered and unordered.

An ordered linked list is a list where the elements are


arranged in ascending or descending.

an unordered linked list is a list where the elements are not


sorted in any particular order.
Linked List Insertion
S.P = 2

A 5 C 9
2 7
B 7 D -1
9
5
How To Insert A Node In A Linked List
Check for a free node in a linked list
Search for correct position
Assign the Value B to the first node in free list
Pointer from B will be changed to point towards C
Pointer from A will point towards B
Start Pointer in free list will move to point to next
free node
Linked List Deletion
S.P = 2

A 5 C 9
2 7
B 7 D -1
9
5
How To Delete A Node In Linked List
Search for the node that you want to delete by
incrementing the pointer and start from the first node
If the node that you want to delete is the first node
then point the start pointer to next node in list
if the node that you want to delete is in the middle
than you would change the pointer value of the
previous node and point it to next node and point the
free list pointer towards the node removed

You might also like