Download as doc or pdf
Download as doc or pdf
You are on page 1of 30

Department of CSE EC 39 / DS and OOPS Lab

M.PRADEEP

EC 39 - DATA STRUCTURES AND OBJECT ORIENTED


PROGRAMMING LAB

SYLLABUS

1. Basic Programs for C++ Concepts

2. Array implementation of List Abstract Data Type (ADT)

3. Linked list implementation of List ADT

4. Cursor implementation of List ADT

5. Stack ADT - Array and linked list implementations

The next two exercises are to be done by implementing the following source files

(a) Program source files for Stack Application 1

(b) Array implementation of Stack ADT

(c) Linked list implementation of Stack ADT

(d) Program source files for Stack Application 2

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))

7. Queue ADT – Array and linked list implementations

8. Search Tree ADT - Binary Search Tree

9. Heap Sort

10. Quick Sort

1
Department of CSE EC 39 / DS and OOPS Lab

List of Experiments

Exp No Name of the Experiment Page No

CYCLE – I

1. C++ basic Programs – Find biggest of n numbers and Find the given 3
number is odd or even.

2. Program to perform array implementation of list ADT 5

3. Program to perform linked list implementation of list ADT 7

4. Program to perform cursor implementation of list ADT 9

5. Program to implementation stack using array and linked list. 11

6. Array and linked list implement of an infix and post fix expression 15
using stack.

CYCLE – II

7. Program to implementation queue using array and linked list. 19

8. Program to implement binary search tree 23

9. Program to implement heap sort 26

10. Program to implement quick sort 28

ADDITIONAL EXPERIMENTS

11 Program to implement insertion sort 29

12 Program to implement bubble sort 30

2
Department of CSE EC 39 / DS and OOPS Lab

EXNO: 1 C++ BASIC PROGRAMS

a. Program to find the biggest among ‘n’ numbers

AIM:
To write a C++ program to find the biggest among ‘n’ numbers.

ALGORITHM:

Step 1: Start

Step 2: Enter the size of the array.

Step 3: Enter the elements of the array.

Step 4: Print the array elements.

Step 5: Initialize the large is equal to the first element of the array.

Step 6: Set a loop up to the array size.

Step 7: Check the next element is greater than the larger, if greater then assign next to the
large.

Step 8: Print the list of largest elements.

Step 9: Stop

OUTPUT:

Enter the number of elements: 5


Enter the elements:
4
5
1
7
3
The Biggest number is : 7

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

b Program to find the given number is odd or even

AIM:
To write a C++ program to find the given number is odd or even.

ALGORITHM:

Step 1: Start

Step 2: Enter the number

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:

Enter the number: 5

The number is odd.

Enter the number: 8

The number is even.

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

EX NO: 2 PROGRAM TO PERFORM ARRAY IMPLEMENTATION OF LIST ADT

AIM:
To write a C program to perform array implementation of list ADT

Problem Description:

A list is a sequence of zero or more elements of a given type a1,a2,a3,…..an ( n>=0)

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

EX NO: 3 PROGRAM TO PERFORM LINKED LIST IMPLEMENTATION OF LIST


ADT

AIM:
To write a C program to perform linked list implementation of list ADT.

ALGORITHM:

1. Linked List Creation:

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

2. Linked List Insertion:

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

3. Linked List Deletion:

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

if node to be deleted not head of list


then
then previous node’s pointer to point to the successor of the node
to be deleted
delete node
else
set list head pointer to point to the successor of the node to be
deleted
delete node
dispose of the node to be deleted
else
write out that the number cannot be deleted

4. Linked List Display:

1. Establish the pointer to the head of the list


2. Print the first number in the list
3. Move the pointer so that it points to the successor of the node
4. Continue until the successor of the node is null

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 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

EX NO: 4 PROGRAM TO PERFORM CURSOR IMPLEMENTATION OF LIST ADT

AIM:

To write a C program to perform cursor implementation of list ADT.

ALGORITHM:

1. Cursor List Insertion:

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

2. Cursor List Deletion:

1. Establish the number to be deleted


2. Find the previous element position from the list
3. Retrieve the previous element position’s next pointer and store its next pointer value into
previous element position’s next pointer
4. Now include the retrieved position into the free list

3. Cursor List Display

1. While the next pointer is equal to 0


do
print the number in the list
move to the position in the next pointer

9
Department of CSE EC 39 / DS and OOPS Lab

OUTPUT:

Enter the number of elements to be created in list : 6


Enter next position of 0: 3 Enter next position of 1: 0 Enter next position of 2: 5
Enter next position of 3: 2 Enter next position of 4: 1 Enter next position of 5: 4
1. Insert 2. Delete 3. Display
Enter your choice: 1
Enter the element to insert: a
Slot Element Next
0 - 5
1 - 0
2 a 0
3 Header 2
4 - 1
5 - 4
1. Insert 2. Delete 3. Display Enter your choice : 1
Enter the element to insert : b
Slot Element Next
0 - 4
1 - 0
2 a 5
3 Header 2
4 - 1
5 b 0
1. Insert 2. Delete 3. Display Enter your choice : 2
Enter the element to delete : b
Slot Element Next
0 - 5
1 - 0
2 a 0
3 Header 2
4 - 1
5 - 4

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

EX NO: 5a PROGRAM TO PERFORM ARRAY IMPLEMENTATION OF STACK ADT

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.

The operations of the stack are,


Push - Insert an item into the stack
Pop - Delete an item from the stack
Peep – Display the top item from the stack

ALGORITHM:

1. Stack Creation / Pushing an item onto the stack:


1. Establish data to be pushed onto the stack
2. If stack not full
then
Enter element into stack and increment top of stack by 1
else
write stack overflow
2. Stack Deletion / Popping an item from the stack:

1. If stack not empty


then
Remove element from stack and decrement top of stack by 1
else
write stack empty
2. Return data from top of stack

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:

Enter the number of elements to be created in stack : 6


Enter the elements: 1 2 3 4 5 6
1. Push 2. Pop 3. Display Enter your choice : 1
Enter the element: 7
1. Push 2. Pop 3. Display Enter your choice : 1
Enter the element: 8
1. Push 2. Pop 3. Display Enter your choice : 2
Popped element : 8
1. Push 2. Pop 3. Display Enter your choice : 3
Stack contents : 1 2 3 4 5 6 7

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

EX NO:5b PROGRAM TO PERFORM LINKED LIST IMPLEMENTATION OF STACK


ADT
AIM:

To write a C program to perform linked list implementation of stack ADT.

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:

1. Stack Creation / Pushing an item onto the stack:

1. Establish data to be pushed onto the stack


2. Create new node and store data
3. Establish link from new element back to its successor
4. Update pointer to top of stack

2. Stack Deletion / Popping an item from the stack:

1. If top of stack pointer not null


then
get pointer to top element
retrieve data from top of stack
reset top of stack pointer to successor of top element and delete node
remove top element from stack
else
write stack empty
2. Return data removed

3. Stack Display:

1. Print the top element from the stack


2. Reset top of stack pointer to successor of top element
3. Continue until the pointer to the top of stack is null

13
Department of CSE EC 39 / DS and OOPS Lab

OUTPUT:

Enter the number of elements to be created in stack : 6


Enter the elements : 1 2 3 4 5 6
1. Push 2. Pop 3. Display
Enter your choice : 1
Enter the element : 7
1. Push 2. Pop 3. Display
Enter your choice : 1
Enter the element : 8
1. Push 2. Pop 3. Display
Enter your choice : 2
Popped element : 8
1. Push 2. Pop 3. Display
Enter your choice : 3
Stack contents : 1 2 3 4 5 6 7

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

EX: NO: 6a ARRAY IMPLEMENTATION OF INFIX EXPRESSION USING STACK


AIM:
To write a C program to implementation an infix expression in array 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:

• Establish data to be pushed onto the stack


• If stack not full
then
Enter element into stack and increment top of stack by 1
else
write stack overflow

Step 3: After Pushing all elements view the stack

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,

3. Stack Deletion / Popping an item from the stack:

• If stack not empty


then
Remove element from stack and decrement top of stack by 1
else
write stack empty
• Return data from top of stack

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

EX: NO: 6b LIST IMPLEMENTATION OF POSTFIX EXPRESSION USING STACK

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:

• Establish data to be pushed onto the stack


• Create new node and store data
• Establish link from new element back to its successor
• Update pointer to top of stack

Step 3: After Pushing all elements view the stack

2. Stack Display:

• Print the top element from the stack


• Reset top of stack pointer to successor of top element
• Continue until the pointer to the top of stack is null

Step 4: To delete an item or element from the stack perform the following steps,

3. Stack Deletion / Popping an item from the stack:

• If top of stack pointer not null


then
get pointer to top element
retrieve data from top of stack
reset top of stack pointer to successor of top element and delete node
remove top element from stack
else
write stack empty
• Return data removed

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

EX NO:7a PROGRAM TO PERFORM ARRAY IMPLEMENTATION OF QUEUE ADT

AIM:

To write a C program to perform array implementation of queue ADT.

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:

1. Queue Creation / Enqueue an item into the queue:

1. Establish the data for insertion


2. Advance the rear according to mechanism for keeping it within array bounds
3. If front not equal to rear then
then
insert data at next available position in the queue
else
queue is full so write out full queue
restore rear marker to its previous value taking into account array bounds.

2. Queue Deletion / Dequeue an item from the queue:

1. If front not equal to rear


then
advance front according to mechanism for keeping it within array bounds
remove element from front of queue
else
write queue empty
2. Return deleted element

3. Queue Display:

Print the elements present between front to rear marker positions

19
Department of CSE EC 39 / DS and OOPS Lab

OUTPUT:

Enter the number of elements to be created in queue : 6


Enter the elements : 1 2 3 4 5 6
1. Enqueue 2. Dequeue 3. Display Enter your choice : 1
Enter the element : 7
1. Enqueue 2. Dequeue 3. Display Enter your choice : 1
Enter the element : 8
1. Enqueue 2. Dequeue 3. Display Enter your choice : 2
Enqueued element : 1
1. Enqueue 2. Dequeue 3. Display Enter your choice : 3
Queue contents : 2 3 4 5 6 7 8

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

EX NO: 7b PROGRAM TO PERFORM LINKED LIST IMPLEMENTATION OF


QUEUE ADT

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:

1. Queue Creation / Enqueue an item into the queue:

1. Establish data to be inserted into the queue


2. Create new node and store data
3. Make created node’s pointer to point to null
4. If not inserting data at the front of the queue
then
adjust the rear node’s pointer so that it points to inserted node
adjust the rear pointer so that it points to inserted node
else
adjust front and rear pointers so that it points to the inserted node
2. Queue Deletion / Dequeue an item from the queue:

1. If front not equal to null


then
retrieve data from front node
adjust the front pointer so that it points to front node’s pointer and delete
node
else
write queue empty
2. Return data removed

21
Department of CSE EC 39 / DS and OOPS Lab

3. Queue Display:

1. Print the element from front node


2. Adjust the front pointer so that it points to front node’s pointer
3. Continue until the front equal to rear

OUTPUT:

Enter the number of elements to be created in queue : 6


Enter the elements : 1 2 3 4 5 6
1. Enqueue 2. Dequeue 3. Display Enter your choice : 1
Enter the element : 7
1. Enqueue 2. Dequeue 3. Display Enter your choice : 1
Enter the element : 8
1. Enqueue 2. Dequeue 3. Display Enter your choice : 2
Enqueued element : 1
1. Enqueue 2. Dequeue 3. Display Enter your choice : 3
Queue contents : 2 3 4 5 6 7 8

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

EX NO: 8 PROGRAM TO IMPLEMENT BINARY SEARCH TREE

AIM:

To write a C program to implement binary search tree.

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:

1. Binary Tree Creation / Insertion:

1. Establish number to be inserted


2. Find where new number is to be placed in the tree using search algorithm
3. Create a new node and store in it the number to be inserted. At the time of insertion this
new node will have no subtrees so its left and right pointes must be set to null
4. If tree is not initially empty
then
if tree number comes numerically later than new number
then
adjust previous node’s left pointer so that it points to the new node
else
adjust previous node’s right pointer so that it points to the new
node
else
adjust root pointer to point to root node

2. Binary Tree Deletion:

1. Establish number to be deleted


2. Search tree for number to be deleted and return pointers to the number to be
deleted and its predecessor if it is present
3. If node to be deleted is found

then

23
Department of CSE EC 39 / DS and OOPS Lab

if node to be deleted is in the left subtree then


then
invoke procedure for deleting node from left subtree
else
invoke procedure for deleting node from right subtree
else
report number to be deleted was not present

3. Deletion from right subtree:

1. Establish pointers to the current node to be deleted and its predecessor


2. Link the predecessor node of the current node to its right subtree
3. Get pointer to the root of the right subtree of the current node and set it as the new
current node pointer
4. Find leftmost node in right subtree by following down a set of left links until a
null is encountered
5. If the node to be deleted has a right subtree
then
make the left subtree of the node to be deleted into the left subtree of the
leftmost node in the right subtree and adjust the root if necessary
else
make the left subtree of the node to be deleted become the right subtree of
the predecessor of the node to be deleted and adjust the root if necessary
6. Dispose of the deleted node

4. Binary Tree Search:

1. Establish the search key


2. Set the not found state and make the current node pointer point to the root and the
previous nose pointer to null
3. While search key not found and there is still a valid path to follow in the tree
do
if search key is not found at the current node
then
save pointer to current node in previous node pointer
if search key is in the left subtree
then
adjust current node pointer to point to the root of left
subtree
else
adjust current node pointer to point to the root of right
subtree

else

24
Department of CSE EC 39 / DS and OOPS Lab

make the not found condition false to indicate termination of


search
4. Establish whether or not search key found
5. Return the status found or not

5. Binary Tree Display:

1. While the tree pointer not null


2. Recursively print the elements in the left subtree
3. Recursively print the elements in the right subtree

OUTPUT:

Enter the number of elements to be created in the tree : 6


Enter the elements : 5 9 6 3 4 1
1. Insert 2. Delete 3. Display Enter your choice : 1
Enter the element : 7
1. Insert 2. Delete 3. Display Enter your choice : 1
Enter the element : 8
1. Insert 2. Delete 3. Display Enter your choice : 3
The elements in tree : 1 3 4 5 6 7 8 9
1. Insert 2. Delete 3. Display Enter your choice : 2
Enter the element : 8
1. Insert 2. Delete 3. Display Enter your choice : 3
The elements in tree : 1 3 4 5 6 7 9

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

EX NO: 9 PROGRAM TO IMPLEMENT HEAP SORT

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:

Name : Heap sort

Operations:

Build() : To insert the elements into the heap

Sort() : To sort the elements in the heap

26
Department of CSE EC 39 / DS and OOPS Lab

ALGORITHM:

Step 1: Read the number of elements to perform the sorting

Step 2: Insert the element into the heap using build function.

Step 3: Sort the list of elements in the heap.

Step 4: Display the result.

OUTPUT:

Enter the number of Elements: 7


Enter the Elements:
6
3
5
2
9
7
1

The Sorted array


1
2
3
5
6
7
9

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

EX NO: 10 PROGRAM TO IMPLEMENT QUICK SORT

AIM:

To write a C program to implement Quick sort.

ALGORITHM:

Step 1: Start

Step 2: Create a class ‘complex’ and declare the necessary variables.

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 6: Print the manipulation of the complex numbers in the file.

Step 7: Stop.

OUTPUT:

Enter the number of Elements: 6


Enter the Elements:
9
3
5
2
7
1

The Sorted array


1
2
3
5
7
9

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

EX NO: 11 PROGRAM TO IMPLEMENT INSERTION SORT

AIM:

To write a C program to implement Insertion sort.

ALGORITHM:

Step 1: Start

Step 2: Read the total number of elements and say it as ‘n’.

Step 3: Set the value of i=0.

Step 4: Compare the adjacent elements.

Step5: Repeat step 4 for all the elements.

Step 6: Increment the value of i and repeat step4, 5 for i<n.

Step 7: Print the sorted list of elements.

Step 8: Stop.

OUTPUT:

Enter the number of elements: 5


Enter the elements:
5
3
8
7
10
Sorted list:
3
5
7
8
10

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

EX NO: 12 PROGRAM TO IMPLEMENT BUBBLE SORT

AIM:

To write a C program to implement Bubble sort.

ALGORITHM:

Step 1: Start

Step 2: Read the total number of elements and say it as ‘n’.

Step 3: Set the value of i=0.

Step 4: Compare the adjacent elements.

Step5: Repeat step 4 for all the elements.

Step 6: Increment the value of i and repeat step4, 5 for i<n.

Step 7: Print the sorted list of elements.

Step 8: Stop.

OUTPUT:

Enter the number of elements: 5


Enter the elements:
5
2
8
9
1
Sorted list:
1
2
5
8
9

RESULT:

Thus the C program to implement bubble sort is written, entered executed and the results
are verified.

30

You might also like