Professional Documents
Culture Documents
Data Structures and Oops - Manual
Data Structures and Oops - Manual
M.PRADEEP
SYLLABUS
The next two exercises are to be done by implementing the following source files
An appropriate header file for the Stack ADT should be #included in (a) and (d)
6. Implement any Stack Application using array implementation of Stack ADT (by
implementing files (a) and (b) given above) and then using linked list implementation of
Stack ADT (by using files (a) and implementing file (c))
9. Heap Sort
1
Department of CSE EC 39 / DS and OOPS Lab
List of Experiments
CYCLE – I
1. C++ basic Programs – Find biggest of n numbers and Find the given 3
number is odd or even.
6. Array and linked list implement of an infix and post fix expression 15
using stack.
CYCLE – II
ADDITIONAL EXPERIMENTS
2
Department of CSE EC 39 / DS and OOPS Lab
AIM:
To write a C++ program to find the biggest among ‘n’ numbers.
ALGORITHM:
Step 1: Start
Step 5: Initialize the large is equal to the first element of the array.
Step 7: Check the next element is greater than the larger, if greater then assign next to the
large.
Step 9: Stop
OUTPUT:
RESULT:
Thus the C++ program to find the biggest among ‘n’ numbers is written entered, executed
and the results are verified.
3
Department of CSE EC 39 / DS and OOPS Lab
AIM:
To write a C++ program to find the given number is odd or even.
ALGORITHM:
Step 1: Start
Step 3: Divide the number that you have entered by 2, if the remainder is 0
then print the given number is even else print the given number is odd.
Step 4: Stop
OUTPUT:
RESULT:
Thus the C++ program to find the given number is odd or even is written entered, executed
and the results are verified.
4
Department of CSE EC 39 / DS and OOPS Lab
AIM:
To write a C program to perform array implementation of list ADT
Problem Description:
n Length of List
a1 First element of list
an Last element of list
n=0 Empty list
Elements can be linearly ordered according to their position in the list
ALGORITHM:
1. List Creation:
1. Establish the number to be created in the list and array S[0..n-1]
2. If inserting new number is (ie. the first element) at the front of the list
then
insert number into the first array position
else
insert number into the next free array position
3. Increment the size of the list
2. List Insertion:
1. Establish the number to be inserted and the position where number is to be inserted
2. Increment the size of the list
3. If the size of the array is greater than size of the list
then
If inserting new number is (ie. the first element) at the front of the list
then
move all elements in the list one position down from their existing
position
insert number into the first array position
else
move to the position specified
move all elements in the list one position down from their existing
position
insert number into the free array position
5
Department of CSE EC 39 / DS and OOPS Lab
else
Decrement the size of the list and write array out of bounds
3. List Deletion:
1. Establish the number to be deleted
2. Search list for number to be deleted
3. If number to be deleted found
then
move all elements in the list one position up from their existing position
decrement the size of the list
else
write element not found
4. List Display:
Print all the numbers from the array position 0 - n-1 in the list
OUTPUT:
Enter the number of elements to be created in list: 3
Enter the elements: 2 3 4
1. Insert 2. Delete 3. Display Enter your choice: 1
Enter the position and number to insert: 1 1
1. Insert 2. Delete 3. Display Enter your choice: 2
Enter the number to delete: 4
1. Insert 2. Delete 3. Display Enter your choice: 3
List: 1 2 3
RESULT:
Thus the C program to perform array implementation of list ADT is written, entered,
executed and the results are verified.
6
Department of CSE EC 39 / DS and OOPS Lab
AIM:
To write a C program to perform linked list implementation of list ADT.
ALGORITHM:
1. Establish the number to be created and the pointer to the head of the list
2. Create new node
3. Store the number in the new node
4. Make created node’s pointer to point to null
5. If inserting new number is (ie. the first element) at the front of the list
then
adjust head of the list pointer so that it points to created node at the head
of list
else
adjust previous node’s pointer so it points to created node
1. Establish the number to be inserted and the pointer to the head of the list
2. Initialize previous node to null and current node pointer to head of list
3. Search list for the insertion position of the number to be inserted and return pointers to their
logical predecessor and successor nodes.
4. Create new node
5. Store the number to be inserted in the new node (inserted node)
6. Adjust inserted node’s pointer so that it points to its logical successor
7. If not inserting new number at the front of the list
then
adjust previous node’s pointer so it points to inserted node
else
adjust head of the list pointer so that it points to inserted node at the head
of list
1. Establish the number to be deleted and the pointer to the head of the list
2. Initialize previous node to null and current node pointer to head of list
3. Search list for number to be deleted and return pointers to their logical
predecessor and the node itself (if found)
4. If number to be deleted found
then
7
Department of CSE EC 39 / DS and OOPS Lab
OUTPUT:
RESULT:
Thus the C program to perform linked list implementation of list ADT is written entered,
executed and the results are verified.
8
Department of CSE EC 39 / DS and OOPS Lab
AIM:
ALGORITHM:
1. Establish the number to be created and the position where number is to be inserted
2. Find the new free cell position from the list
3. Store the number in that position
4. Adjust the position to be inserted next pointer to new number’s next pointer
5. Store the position to be inserted next pointer with new free cell position
9
Department of CSE EC 39 / DS and OOPS Lab
OUTPUT:
RESULT:
Thus the C program to perform cursor implementation of list ADT is written entered,
executed and the results are verified.
10
Department of CSE EC 39 / DS and OOPS Lab
AIM:
To write a C program to perform array implementation of stack ADT.
DESCRIPTION:
A collection of items in which only the most recently added item may be removed. The latest
added item is at the top. Also known as "last-in, first-out" or LIFO.
ALGORITHM:
3. Stack Display:
Print the elements from the top of stack by decrementing the top of stack value
till it reaches 0
11
Department of CSE EC 39 / DS and OOPS Lab
OUTPUT:
RESULT:
Thus the C program to perform array implementation of stack ADT is written entered,
executed and the results are verified.
12
Department of CSE EC 39 / DS and OOPS Lab
DEFINITION OF STACK:
A collection of items in which only the most recently added item can be removed. The
latest added item is at the top. Also known as ‘last-in first-out’ or LIFO.
ALGORITHM:
3. Stack Display:
13
Department of CSE EC 39 / DS and OOPS Lab
OUTPUT:
RESULT:
Thus the C program to perform linked list implementation of stack ADT is written,
entered, executed and the results are verified.
14
Department of CSE EC 39 / DS and OOPS Lab
2. Stack Display:
Print the elements from the top of stack by decrementing the top of
stack value till it reaches 0
Step 4: To delete an item or element from the stack perform the following steps,
15
Department of CSE EC 39 / DS and OOPS Lab
OUTPUT:
Stack input read from the file: ((3 + 2) * 4) / (5 - 1)
1. Push 2. Pop 3. Display
Enter your choice : 1
Enter the element : 3
1. Push 2. Pop 3. Display
Enter your choice : 1
Enter the element : 2
1. Push 2. Pop 3. Display
Enter your choice : 3
Stack contents : 3 2
1. Push 2. Pop 3. Display
Enter your choice : 2
Popped element : 2
1. Push 2. Pop 3. Display
Enter your choice : 3
Stack contents : 3
RESULT:
Thus the C program to implementation an infix expression in array using stack is written,
entered, executed and the results were verified.
16
Department of CSE EC 39 / DS and OOPS Lab
AIM:
To write a C program to implementation a postfix expression in linked list using stack.
ALGORITHM:
Step 1: Create a source file and write some expressions in the file
Step 2: Read the expression one by one from the file and push on to the stack
1. Stack Creation / Pushing an item onto the stack:
2. Stack Display:
Step 4: To delete an item or element from the stack perform the following steps,
17
Department of CSE EC 39 / DS and OOPS Lab
OUTPUT:
Stack input read from the file: 321-+
1. Push 2. Pop 3. Display
Enter your choice : 1
Enter the element : 3
1. Push 2. Pop 3. Display
Enter your choice : 1
Enter the element : 2
1. Push 2. Pop 3. Display
Enter your choice : 3
Stack contents : 3 2
1. Push 2. Pop 3. Display
Enter your choice : 2
Popped element : 2
1. Push 2. Pop 3. Display
Enter your choice : 3
Stack contents : 3
RESULT:
Thus the C program to implementation a postfix expression in linked list using stack is
written, entered, executed and the results were verified.
18
Department of CSE EC 39 / DS and OOPS Lab
AIM:
DEFINITION OF QUEUE:
A collection of items in which only the earliest added item can be accessed. Basic
operations are add or enqueue and delete or dequeue. Delete returns the item removed.
Also known as “First-In First-Out or FIFO.
ALGORITHM:
3. Queue Display:
19
Department of CSE EC 39 / DS and OOPS Lab
OUTPUT:
RESULT:
Thus the C program to perform array implementation of queue ADT is written entered,
executed and the results are verified.
20
Department of CSE EC 39 / DS and OOPS Lab
AIM:
To write a C program to perform linked list implementation of queue ADT.
DESCRIPTION:
A collection of items in which only the earliest added item may be accessed. Basic operations are
add (to the tail) or enqueue and delete (from the head) or dequeue. Delete returns the item
removed. Also known as "first-in, first-out" or FIFO.
The operations of queue are,
Enqueue : Inserts an element at the end of the queue.
Dequeue : Removes an element at the front of the queue.
Display : Display the list of elements present in the queue.
ALGORITHM:
21
Department of CSE EC 39 / DS and OOPS Lab
3. Queue Display:
OUTPUT:
RESULT:
Thus the C program to perform linked list implementation of queue ADT is written
entered, executed and the results are verified.
22
Department of CSE EC 39 / DS and OOPS Lab
AIM:
DESCRIPTION:
A Tree is a widely-used data structure that emulates a tree structure with a set of linked
nodes. It is an acyclic and connected graph. The topmost node in a tree is called the root node.
Leaf nodes
Nodes at the bottommost level of the tree are called leaf nodes. Since they are at the
bottommost level, they do not have any children.
A binary tree is a finite set of nodes which is either empty or consists of a root and two
disjoint binary trees called the left subtree and the right subtree.
ALGORITHM:
then
23
Department of CSE EC 39 / DS and OOPS Lab
else
24
Department of CSE EC 39 / DS and OOPS Lab
OUTPUT:
RESULT:
Thus the C program to implement binary search tree is written, entered, executed and the
results are verified.
25
Department of CSE EC 39 / DS and OOPS Lab
AIM:
To write a C program to implement heap sort.
DESCRIPTION:
A heap sort is a complete binary tree which is either empty or satisfies the following
conditions:
The priority of the root is higher than (or equal to) that of its children.
The left and right sub trees of the root are heap-trees.
An alternative definition: A heap tree is a complete binary tree such that the priority of
every node is higher that (or equal to) that of all its descendents. Yet another say is that
every path as every one goes down in the tree, the values become smaller. The first
obvious difference to binary search trees is that the biggest number now occurs at the root
at the root (rather than the right most nodes). Secondly, where as binary search trees, the
left and right child of a node played very important role, whereas now they will be
interchangeable.
Example:
2
1
1
6
1
Design Approach:
Operations:
26
Department of CSE EC 39 / DS and OOPS Lab
ALGORITHM:
Step 2: Insert the element into the heap using build function.
OUTPUT:
RESULT:
Thus the C program to implement heap sort is written, entered, executed and the results are
verified.
27
Department of CSE EC 39 / DS and OOPS Lab
AIM:
ALGORITHM:
Step 1: Start
Step 3: Generate the complex numbers randomly by the specified functions in the class
Step 4: Write the complex numbers into a file along with an operator.
Step 5: Read the complex numbers written to the file and perform the addition,
subtraction, multiplication and division of the complex numbers.
Step 7: Stop.
OUTPUT:
RESULT:
Thus the C program to implement Quick sort is written, entered executed and the results
are verified.
28
Department of CSE EC 39 / DS and OOPS Lab
AIM:
ALGORITHM:
Step 1: Start
Step 8: Stop.
OUTPUT:
RESULT:
Thus the C program to implement insertion sort is written, entered executed and the
results are verified.
29
Department of CSE EC 39 / DS and OOPS Lab
AIM:
ALGORITHM:
Step 1: Start
Step 8: Stop.
OUTPUT:
RESULT:
Thus the C program to implement bubble sort is written, entered executed and the results
are verified.
30