You are on page 1of 47

WWW.VIDYARTHIPLUS.

COM

www.rejinpaul.com

RAJALAKSHMI INSTITUTE OF
TECHNOLOGY

DEPARTMENT OF INFORMATION
TECHNOLOGY

LAB MANUAL

EC6312 OBJECT ORIENTED
PROGRAMMING AND DATA
STRUCTURES LAB
(III SEMESTER ECE)

Prepared by:
Ms. M.LEELA AP/IT
Mr.M.RAMASWAMY AP/IT

www.rejinpaul.com
www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.rejinpaul.com

EC6312 OOPS AND DATA STRUCTURES LABORATORY
LIST OF EXPERIMENTS:

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
6. The next two exercises are to be done by implementing the following source files
i. Program source files for Stack Application 1
ii. Array implementation of Stack ADT
iii. Linked list implementation of Stack ADT
iv. Program source files for Stack Application 2
v. An appropriate header file for the Stack ADT should be included in (i) and (iv)
7. Implement any Stack Application using array implementation of Stack ADT (by
implementing files (i) and (ii) given above) and then using linked list
8. Implementation of Stack ADT (by using files (i) and implementing file (iii))
9. Implement another Stack Application using array and linked list implementations of
Stack ADT (by implementing files (iv) and using file (ii), and then by using files (iv) and
(iii))
11. Queue ADT – Array and linked list implementations
12. Search Tree ADT - Binary Search Tree
13. Implement an interesting application as separate source files and using any of the
searchable ADT files developed earlier. Replace the ADT file alone with other appropriate
ADT files. Compare the performance.
14. Quick Sort

\\\\

www.rejinpaul.com
www.Vidyarthiplus.com

2

www.Vidyarthiplus.com

www.rejinpaul.com

DEFAULT ARGUMENTS

Ex. No: 1a

Aim:
To implement function with default arguments.
Algorithm:
1.
2.
3.

Declare the default function.
Invoke the default function.
Display the result

Program:

Output:
-------- --------------------------///////////////////////////////////////
****************************
RRRRRRRRRRRRRRRRRRRRRRR

Result:
Thus the given program function with Default Arguments was implemented
successfully.

www.rejinpaul.com
www.Vidyarthiplus.com

3

www.Vidyarthiplus.com

Ex. No: 1b

www.rejinpaul.com

CLASS WITH STATIC DATA MEMBER

Aim:
To implement static data member in class.
Algorithm:
1.
2.
3.
4.

Create class ITEM with static data member as count.
Create a member function to increment the count.
Declare the static datamember using scope resolution operator.
Display the count value.

Program:
Output:
count
count
count
Number
Number
Number
count
count
count

0
0
0
20
30
40
3
3
3

Result:
Thus the given program static data member in class was implemented successfully.

www.rejinpaul.com
www.Vidyarthiplus.com

4

3.rejinpaul. Algorithm: 1.Vidyarthiplus.com www. 4.com www.www. 5.rejinpaul. Create a class Define the function Enter the real and imaginary values Define the function for adding the values Display the result Program: Output: Enter the real & img part 3 3 Enter the real & img part 4 7 The complex number of c1 : 3+3i The complex number of c2 : 4+7i The result is 7+10i Result: Thus the given program addition of two complex numbers was implemented successfully.com Ex.Vidyarthiplus. No: 1c ADDITION OF TWO COMPLEX NUMBERS Aim: To implement addition of two complex numbers. www.com 5 . 2.

rejinpaul. Algorithm: 1. Program: Output: Enter the student name and mark Priya 98 89 79 The student name and marks Priya 98 89 79 The student total & average 266 88. The class complex contains two member variables real and imaginary.Vidyarthiplus. Display temp. Add imaginary part with imaginary of other object and store it in temp’s imaginary. No: 1d CREATION OF CLASS AND OBJECTS www. 2.com Aim: To write a program for creating class and objects. 4.rejinpaul. 3.com Ex. Declare a temporary variable temp.www.Vidyarthiplus. Assign the value for real and imaginary part. 6. 5.com www.67 Result: Thus the given program student mark details using class and objects was implemented successfully. Add real part with real of other object and store it in temp’s real.com 6 . www.

com 7 .com www.www.Vidyarthiplus. www. Algorithm: 1.com Ex.rejinpaul. Declare the function 2.com CALL BY VALUE www.rejinpaul. Enter the values for a & b 3. No:1e Aim: To write a c++ program for Call By Value. Display the result Program: Output: Enter the value for a and b 79 The value of a&b inside the function is 35 63 The value of a and b after execution The function is 7 9 Result: Thus the given program Call By Value was implemented successfully.Vidyarthiplus. Define the function 4.

com CALL BY REFERENCE Ex. 2. Algorithm: 1.com www.com 8 .www.rejinpaul.Vidyarthiplus. Declare the function Enter the values for a& b Define the function Print the output Program: Output: Enter the value for a and b 57 The value of a & b inside the function is 25 49 The value of a & b after execution The function is 25 49 . Result: Thus the given program Call By Reference was implemented successfully. 3.Vidyarthiplus. 4.rejinpaul. No: 1f Aim: To write a c++ program for Call By Reference . www.com www.

Vidyarthiplus.265482 Result: Thus the given program for finding area of circle.rejinpaul. square and rectangle was executed successfully.Create another function with the same name. Call the function. 3. Declare the variables.rejinpaul. Define the function. Algorithm: 1.com FUNCTION OVERLOADING Aim: To write a c++ program for function Overloading .com www.com 9 .com Ex. www. Program: Output: Enter the side of square 4 Area of the square 16 Enter the length & breath values 6 4 Area of the rectangle 24 Enter the radius of circle 4 Area of the circle 50.Vidyarthiplus. 6. No: 1g www. 4. 5. Define the main function and declare the variables. Define the class 2.www.

Program: Create the class.20 Enter the second number….Vidyarthiplus. Display the result. Perform the operation of finding greatest number in the friend function.No:1h Aim: To Write a C++ program for implementing Friend Function. www. 2.com www. Declare the friend function using the keyword friend.rejinpaul.com www.rejinpaul.www.com FRIEND FUNCTION Ex. Algorithm: 1.com 10 . 3. .Vidyarthiplus. 4.10 Greater number is 20 Result: Thus the given program using friend function was implemented successfully. Output: Enter the first number….

com FUNCTION AND DEFAULT FUNCTION Ex.Vidyarthiplus.Vidyarthiplus. 3. FRIEND www. friend and default function. Define class. 6. Call the Different task of function. 2.No:1i Aim: To Write a C++ program for implementing the Matrix Multiplication using static. Print the output.rejinpaul.www. Algorithm: 1.friend and default function was executed successfully. Define main function 4. Declare the variables.com 11 . www. Program: Output: Enter the matrix of size 2x2 98 98 Enter the matrix of size 2x2 98 98 The matrix A: 98 98 The matrix B: 98 98 The resultant matrix (A+B): 18 16 18 16 The resultant matrix (A*B): 162 128 162 128 Result: Thus the given program Matrix Multiplication using static .com MATRIX MULTIPLICATION USING STATIC. Define the functions with different arguments.rejinpaul. 5.com www.

Define main function 4. Define class. Call the Different task of function.com CONSTRUCTOR Ex.No:1j Aim: To Write a C++ program for using Constructor. www. 6. Print the output.com www. Declare the variables.rejinpaul. 3. Define the constructor.com www.Vidyarthiplus. 2. Program: Output: First input 21+i34 Second input 23+i23 The sum is : 44+i57 Result: Thus the given program addition of complex numbers using constructor was executed successfully.rejinpaul. Algorithm: 1.Vidyarthiplus.www.com 12 . 5.

rejinpaul. Define class.com www. Algorithm: 1. Declare the variables. Print the output. www.www.No:1k Aim: To Write a C++ program for implementing the Multiplication of two numbers using Inheritance. 2.com Ex.com INHERITANCE www.Vidyarthiplus. 3. Call the Different task of function. Program: Output: Enter the two number 5 6 Multiplication value is 30 Result: Thus the given program Multiplication of two numbers using Inheritance was executed successfully.com 13 .rejinpaul. 5.Vidyarthiplus. Define the functions without arguments. 6. Define main function 4.

4.rejinpaul. 5.rejinpaul.Vidyarthiplus. 4. Program Output program for implementing list using array main menu 1.www.com www.com Ex. 4. Insert Data in to the List . 6. 2. Create a struct for each node .Vidyarthiplus. creation display insertion of element in the list deletion of element from the list Searching of element from the list exit enter your choice 1 enter the index for first node 4 enter the data and index of the first element 10 1 enter the data and index of the first element 20 6 enter the data and index of the first element 30 7 enter the data and index of the first element 40 -1 do you wish to go to main menu? program for implementing list using array main menu 1.com www. Search the data in to the List. 3. creation display insertion of element in the list deletion of element from the list Searching of element from the list exit enter your choice 2 10->20->30->40->null www. No: 2 IMPLEMENTATION OF VARIOUS LIST OPERATIONS USING ARRAYS Aim: To implement the various list operations using Arrays. The operations are a)Insert b)delete c)searchd)display 3. Delete the Data in to the List. 5. 2. Algorithm: 1. 2. 6.com 14 . 3. 5.

4. 6. 6. creation display insertion of element in the list deletion of element from the list Searching of element from the list exit enter your choice 3 enter the new data which is to be inserted 21 enter the data after which you want to insert 20 do you wish to go to main menu? program for implementing list using array main menu 1. 3. creation display insertion of element in the list deletion of element from the list Searching of element from the list exit enter your choice 4 enter the node to be deleted 30 do you wish to go to main menu? program for implementing list using array www. 3. 4. 3.rejinpaul.com program for implementing list using array main menu 1. 2. 5. 2.www. creation display insertion of element in the list deletion of element from the list Searching of element from the list exit enter your choice 2 10->20->21->30->40->Null do you wish to go to main menu? program for implementing list using array main menu 1.com 15 . 6.Vidyarthiplus.com do you wish to go to main menu? www. 2.rejinpaul. 4.com www. 5. 5.Vidyarthiplus.

display www. 5. 5. 6. 2.com www.www. 6.rejinpaul.Vidyarthiplus.Vidyarthiplus. 4. 6.com main menu 1. creation display insertion of element in the list deletion of element from the list Searching of element from the list exit enter your choice 5 enter the node to be searched 30 the node is not present do you wish to go to main menu? program for implementing list using array main menu 1.com enter your choice 2 10->20->21->40->null do you wish to go to main menu? program for implementing list using array main menu 1. 3.com 16 . 2. 3. creation display insertion of element in the list deletion of element from the list Searching of element from the list exit www. 3. creation 2.rejinpaul. 4. 5. 4. creation display insertion of element in the list deletion of element from the list Searching of element from the list exit enter your choice 5 enter the node to be searched 20 the 20 node is present in the list do you wish to go to main menu? program for implementing list using array main menu 1. 2.

insertion of element in the list deletion of element from the list Searching of element from the list exit www.com www. 6. www.com enter your choice 6 Result: Thus the Array implementation of List ADT program was executed successfully.Vidyarthiplus.rejinpaul.Vidyarthiplus.www. 5.com 3. 4.com 17 .rejinpaul.

e. Algorithm: Step 1 : Start the process. Step 3: Enter the choice.com LINKED LIST IMPLEMENTATION USING LISTADT www. Step 6: Stop the process.com Ex. b. c. Print the linked list after deletion.Vidyarthiplus. b. d. Adjust the link fields so that PAR points to the next element.rejinpaul. Find the node containing the element (LOC) and its preceding node (PAR).com www. www. Print the linked list after insertion. c.com 18 . ie LINK[PAR] = LINK [ LOC]. Enter the element to be inserted. Step 5: If choice is DELETE then a. No: 3 Aim To implement a linked list and do all operations on it. Step 2: Initialize and declare variables. Step 4: If choice is INSERT then a.www.Vidyarthiplus. Enter the element to be deleted. d. Set ITEM = DATA[LOC] and delete the node LOC. Find the node after which the new node is to be inserted. e. Get a new node and set DATA[NEWNODE] = ITEM. Adjust the link fields.rejinpaul.

rejinpaul. display 3.com program: www.www. display www.create 2.delete an element from list 6.rejinpaul.com www.com output program to perform various operations on linked list 1.quit enter your choice(1-6) 1 enter the data: 10 do you want to enter more elements?(y/n)y enter the data 20 do you want to enter more elements?(y/n)y enter the data 30 do you want to enter more elements?(y/n)y enter the data 40 do you want to enter more elements?(y/n)y enter the data 50 do you want to enter more elements?(y/n)n the singly linked list is created continue? program to perform various operations on linked list 1.search 4.insert an element in a list 5.Vidyarthiplus.com 19 .Vidyarthiplus.create 2.create 2.quit enter your choice(1-6) 2 10 20 30 40 50 continue? program to perform various operations on linked list 1.delete an element from list 6. display 3.search 4.insert an element in a list 5.

quit enter your choice(1-6) 3 enter the element you want to search 30 www.search 4. display 3.rejinpaul.insert after 3.com 3.create 2.insert after 3.delete an element from list 6.quit enter your choice(1-6) 4 the list is: 10 20 30 40 50 menu 1.insert an element in a list 5.delete an element from list 6.com 20 . display 3.rejinpaul.search 4.Vidyarthiplus.insert at end enter your choice 1 enter the element which you want to insert 9 continue? program to perform various operations on linked list 1.inset at beginning 2.search 4.com www.inset at beginning 2.delete an element from list 6.insert an element in a list 5.com the element is present in the list continue? program to perform various operations on linked list 1.insert at end enter your choice 2 www.quit enter your choice(1-6) 4 the list is: 9 10 20 30 40 50 menu 1.Vidyarthiplus.insert an element in a list 5.create 2.www.

display 3.insert after 3.quit enter your choice(1-6) 5 enter the data of the node you want to delete :10 the element is deleted www.search 4.Vidyarthiplus.rejinpaul.insert an element in a list 5.delete an element from list 6.com enter the element which you want to insert 31 enter the element after which you want to insert the node 30 continue? program to perform various operations on linked list 1.create 2.rejinpaul.www.inset at beginning 2.com www.delete an element from list 6.insert at end enter your choice 3 enter the element which you want to insert 60 continue? program to perform various operations on linked list 1.Vidyarthiplus.create 2.create 2.insert an element in a list 5. display 3.com www.search 4. display 3.quit enter your choice(1-6) 2 9 10 20 30 31 40 50 60 continue? program to perform various operations on linked list 1.delete an element from list 6.search 4.quit enter your choice(1-6) 4 the list is: 9 10 20 30 31 40 50 menu 1.com 21 .insert an element in a list 5.

quit enter your choice(1-6) 2 9 20 30 31 40 50 60 Result Thus the given program Linked List implementation of the list ADT was executed successfully.com www. display 3.com www.com continue? program to perform various operations on linked list 1.com 22 .rejinpaul.search 4.Vidyarthiplus.rejinpaul.delete an element from list 6.insert an element in a list 5.create 2. www.Vidyarthiplus.www.

middle or end position of insertion.Vidyarthiplus.rejinpaul. Stop the program. 4. Program: Output program to perform operations on ordered list 1. o Allocate space for the node dynamically. Algorithm: 1. For insertion get the position in which insertion is to be done and the element to be inserted.display 3.com Ex. Insert the node and change its link accordingly.rejinpaul. Check for the start. Using display option list the elements of the list. Delete the node and then link it to the next node. Create a node with two fields data and link field. 3.display www.com 23 .search for a number 4.Quit enter your choice(1-6) 1 how many elements you want in the list:5 Enter the element number 1 :10 Enter the element number 2 :20 Enter the element number 3 :30 Enter the element number 4 :40 Enter the element number 5 :50 The List is successfully created program to perform operations on ordered list 1.No:4 Aim: To write a C++ program for cursor implementation of list ADT.delete 6. Start the program.www.reverse 5. 6.com www. Before deletion check whether there is data in the list to be deleted. For deletion get the position in which deletion is to be done.create 2. Get the choice of operations either insertion or deletion. 2.com CURSOR IMPLEMENTATION – LIST ADT www. 5. o Create link between the created nodes and let the last node be with NULL Link o Insert the input data in the data field and press –1 to stop the same.Vidyarthiplus.create 2. 7.

create 2.search for a number 4.com enter your choice(1-6)2 the lis is… 10 20 30 40 50 press the key to continue… program to perform operations on ordered list 1.Vidyarthiplus. 50 40 30 20 10 press the key to continue… program to perform operations on ordered list 1.delete 6.create 2.search for a number 4.display 3.rejinpaul.www.reverse 5.delete 6.Vidyarthiplus.Quit enter your choice(1-6) 4 the reversed list is ….display 3..reverse 5.display 3.rejinpaul.com 24 .reverse 5.delete 6.com www.search for a number 4.delete www.Quit enter your choice(1-6) 3 enter the number you want to search? 20 the given number is at position 1 program to perform operations on ordered list 1.Quit www.create 2.com 3.search for a number 4.reverse 5.

display 3.create 2.com www.Quit enter your choice(1-6) 2 the list is… 10 -1 30 40 50 press the key to continue… program to perform operations on ordered list 1.Quit enter your choice(1-6) 6 do you want to exit(y/n)?n Result: Thus the given program Cursor implementation of list was executed successfully.reverse 5.Quit enter your choice(1-6) 5 enter the number you want to search? 20 the given number is at position 1 the element is now deleted! we put -1 to indicate empty location program to perform operations on ordered list 1.com 6.delete 6.rejinpaul.reverse 5.Vidyarthiplus.search for a number 4.www.Vidyarthiplus.com www.create 2.rejinpaul.delete 6.search for a number 4.com 25 .display 3. www.

com www. 3c. the link of the node is NULL.rejinpaul. the pervious TOP is popped from stack.If TOP is NOT NULL the link of TOP points to the new node. Step 5. No:5a Aim: To write a program for stack using array implementation.com 26 .If TOP is NULL the stack is empty 4b. Algorithm: Step1:Define a array which stores stack elements.If TOP is NOT NULL the link of TOP is the current TOP. Step 4: POP DATA FROM STACK 4a.exit enter your choice 1 www. Program: Output: implementation of stack main menu 1..pop 3.Vidyarthiplus.If TOP is NULL the input data is the first node in stack. 3b. The stack represented by linked list is traversed to display its content.display 4. Step 2: The operations on the stack are a)PUSH data into the stack b)POP data out of stack Step 3: PUSH DATA INTO STACK 3a.rejinpaul.com www. TOP points to that node.com STACK ADT USING ARRAY IMPLEMENTATION Ex. TOP points to that node.Vidyarthiplus.push 2.Enter the data to be inserted into stack.www.

pop 3.Vidyarthiplus.push 2.pop 3.exit enter your choice 2 the popped element is 20 do you want to continue? y main menu 1.display 4.rejinpaul.exit enter your choice 1 enter the item to be pushed 20 do you want to continue? y main menu 1.Vidyarthiplus.push 2.display 4.com www.rejinpaul.com main menu 1.pop 3.push 2.display 4.www.exit enter your choice 2 the popped element is 30 do you want to continue? y main menu 1.display 4.com 27 .com enter the item to be pushed 10 do you want to continue? y www.display www.pop 3.push 2.push 2.exit enter your choice 3 20 10 do you want to continue? y main menu 1.pop 3.

com 4.push 2.www.Vidyarthiplus.com www. www.com www.display 4.exit enter your choice 2 empty stack! Underflow !! do you want to continue Result: Thus the given program stack ADT using array implemented successfully.rejinpaul.com 28 .rejinpaul.exit enter your choice 2 the popped element is 10 do you want to continue? y main menu 1.pop 3.Vidyarthiplus.

If TOP is NULL the stack is empty 4b.pop 3.push 2. Program: Output: stack using linked list the main menu 1. No:5b Aim: To write a program for stack ADT using linked list implementation.exit www.www. TOP points to that node.rejinpaul. 3b. Step 2: The operations on the stack are a)PUSH data into the stack b)POP data out of stack Step 3: PUSH DATA INTO STACK 3a.com www. Algorithm: Step1:Define a struct for each node in the stack.com STACK ADT USING LINKED LIST IMPLEMENTATION Ex.rejinpaul. Step 5.If TOP is NOT NULL the link of TOP is the current TOP.Enter the data to be inserted into stack. Each node in the stack contains data and link to the next node. the pervious TOP is popped from stack.Vidyarthiplus.com www. TOP pointer points to last node inserted in the stack. 3c.Vidyarthiplus. the link of the node is NULL.If TOP is NULL the input data is the first node in stack. The stack represented by linked list is traversed to display its content.If TOP is NOT NULL the link of TOP points to the new node.display 4. TOP points to that node.com 29 . Step 4: POP DATA FROM STACK 4a.

push 2.exit enter your choice 1 enter the data 20 do you want to continue? y the main menu 1.display 4.pop 3.exit enter your choice 1 enter the data 40 do you want to continue? y the main menu 1.pop 3.com enter your choice 1 enter the data 10 www.com 30 .pop 3.display 4.www.display 4.pop 3.rejinpaul.push 2.pop www.exit enter your choice 1 enter the data 30 do you want to continue? y the main menu 1.push 2.exit enter your choice 1 enter the data 50 do you want to continue? y the main menu 1.com www.rejinpaul.push 2.Vidyarthiplus.push 2.com do you want to continue? the main menu 1.Vidyarthiplus.display 4.

rejinpaul.exit enter your choice 2 the poped node is 50 www.pop 3.Vidyarthiplus.Vidyarthiplus.com 3.push 2.com www.www.com 31 . www.exit enter your choice 3 50 40 30 20 10 do you want to continue? y the main menu 1.com do you want to continue? y the main menu 1.rejinpaul.push 2.display 4.display 4.exit enter your choice 4 Result: Thus the given program for stack ADT using linked list implementation was executed successfully.pop 3.display 4.

www.Vidyarthiplus. the implementation of stack is using arrays.com 32 .com www.h Step 2: Now we will create a stack application program. stack. in this frile we will declare the class and all the stack operations. Output(run 1) program for stack application using separate header file enter the expression and put $ at the end (()(()))$ the expression has well formed parenthesis Output(run 2) program for stack application using separate header file enter the expression and put $ at the end (()()$ the expression in invalid. We have chosen an application as “checking well formedness of parenthesis” for this application we will use stack operations.com PROGRAM SOURCE FILES FOR STACK APPLICATION1 Application 1: checking well formedness of parenthesis.Vidyarthiplus. A) STACK IMPLEMENTED AS ARRAYS(USING THE HEADER FILE OF STACK OPERATIONS) Step 1: Crate a header file named stack. Hence we will include this file in the include file section. These operations are used from the external file stack.www.h . Here is an application program.com Ex. Result: Thus the given program checking well formedness of parenthesis stack implemented as arrays was executed successfully.rejinpaul.rejinpaul. No: 6 www.h.

Result: Thus the given program checking well formedness of parenthesis stack implemented as Linked List was executed successfully.rejinpaul.com 33 .h.www.com B) STACK IMPLEMENTED AS LINKED LIST(USING THE HEADER FILE OF STACK OPERATION) step 1: create a header file named stack. www. The implementation of stack using linked list. Here is an application program.Vidyarthiplus. Step 2: Now we will create a stack application program.com www. In this file we declare the class and all the stack operations. These operations are used from the external file stack. We have chosen an application as “checking well formedness of parenthesis” for this application we will use stack operations. Step 3: The above program will be executed to get output as follows output(run1) enter the expression and put $ at the end ()()$ the expression has well formed parenthesis output(run 2) enter the expression and put $ at the end (()()$ the expression is invalid.Vidyarthiplus.com www.rejinpaul. Hence we will include this file in the include file section.

Vidyarthiplus.rejinpaul.com www. www.rejinpaul.her the stack using arrays is implemented in separate file named stack.com www. A. No: 6 PROGRAM SOURCE FILES FOR STACK APPLICATION2 application 2: Evaluation of postfix expression.Vidyarthiplus.www.com Ex.h ************************************************************************/ Output: Enter the postfix expression 12+3* The value of the expression is 9 Result: Thus the given program Evaluation of postfix expression stack implemented as arrays was executed successfully.USING STACK(IMPLEMENTATION AS ARRAYS) STEP 1: /******************************************** stack.com 34 .h *********************************************/ STEP 2: /************************************************************************ program to evaluate a given postfix expression .

Vidyarthiplus.h is a user defined header file created for linked stack **********************************************************************/ Output: enter the expression 12+3* the value of the expression is 9 Result: Thus the given program Evaluation of postfix expression stack implemented as Linked List was executed successfully.com www.rejinpaul.www. here stack.com B.rejinpaul.Vidyarthiplus. STACK IMPLANTED AS LINKED LIST(USE OF SEPARATE HEADER FILE FOR STACK OPERATIONS) STEP 1: STEP 2: /********************************************************************* program to evaluate a given postfix expression using linked stack.com 35 .com www. www.

Algorithm: Step1:Define a array which stores queue elements. No:11 Aim: To write a program for Queue using array implementation. Step 2: The operations on the queue are a)INSERT data into the queue b)DELETE data out of queue Step 3: INSERT DATA INTO queue 3a.com www.rejinpaul.If TOP is NOT NULL the link of TOP points to the new node. Step 5.Vidyarthiplus.If TOP is NULL the queue is empty 4b.rejinpaul.com www.If TOP is NULL the input data is the first node in queue.If TOP is NOT NULL the link of TOP is the current TOP. 3b. 3c.com 36 . Program: /****************************************************** Program for implementing the queue using arrays *******************************************************/ Output: main menu 1. The queue represented by linked list is traversed to display its content. TOP points to that node.delete 3.com QUEUE ADT USING ARRAY IMPLEMENTATION Ex.insert 2. TOP points to that node. the pervious TOP is popped from queue.Enter the data to be inserted into queue.www.. Step 4: DELETE DATA FROM queue 4a. the link of the node is NULL.display www.Vidyarthiplus.

rejinpaul.delete 3.com www.delete 3.display www.display enter your choice 1 enter the number to be inserted 40 do you want to continue?y main menu 1.Vidyarthiplus.display enter your choice 2 www.display enter your choice 3 10 20 30 40 do you want to continue?y main menu 1.insert 2.com 37 .www.Vidyarthiplus.com enter your choice 1 enter the number to be inserted 10 do you want to continue?y main menu 1.com enter your choice 1 enter the number to be inserted 20 do you want to continue?y main menu 1.delete 3.insert 2.delete 3.display enter your choice 1 enter the number to be inserted 30 do you want to continue?y main menu 1.insert 2.insert 2.insert 2.rejinpaul.delete 3.insert 2.delete 3.display enter your choice 2 the deleted item is 10 do you want to continue?y main menu 1.

Vidyarthiplus.rejinpaul.com 38 .www.insert 2.delete 3.com the deleted item is 20 do you want to continue?y main menu 1. www.com www.com Result: Thus the given program for Queue using array implementation was executed successfully.rejinpaul.display enter your choice 3 30 40 do you want to continue? www.Vidyarthiplus.

3b. 3c. delete 3.display www.com 39 . Each node in the queue contains data and link to the next node.rejinpaul.com Ex.If TOP is NULL the queue is empty 4b. Step 2: The operations on the queue are a)INSERT data into the queue b)DELETE data out of queue Step 3: INSERT DATA INTO queue 3a. TOP points to that node.www.If TOP is NOT NULL the link of TOP points to the new node.Vidyarthiplus. No:11b QUEUE ADT OPERATIONS USING LINKED LIST Aim: To write a C++ program for Queue using Linked implementation. the pervious TOP is popped from queue. The queue represented by linked list is traversed to display its content.If TOP is NULL the input data is the first node in queue.com www. Step 4: DELETE DATA FROM queue 4a.Vidyarthiplus. the link of the node is NULL.com www. Algorithm: Step1: Define a struct for each node in the queue.rejinpaul.Enter the data to be inserted into queue. Front and rear pointer points to first and last node inserted in the queue. Program: Output program for queue using linked list main menu 1.If TOP is NOT NULL the link of TOP is the current TOP.insert 2. Step 5. TOP points to that node.

Vidyarthiplus.display enter your choice 1 insert the element in the queue 30 do you want main menu?(y/n) y program for queue using linked list main menu 1.rejinpaul. delete 3.www.com www.com www.rejinpaul.display enter your choice 1 insert the element in the queue 40 do you want main menu?(y/n) y program for queue using linked list main menu 1.display enter your choice 1 insert the element in the queue 20 do you want main menu?(y/n) y program for queue using linked list main menu 1.com 40 . delete 3.insert 2.com enter your choice 1 insert the element in the queue 10 do you want main menu?(y/n) y program for queue using linked list main menu 1.insert 2. delete www.Vidyarthiplus.insert 2.insert 2. delete 3.

rejinpaul.Vidyarthiplus.display enter your choice 3 the display of queue is 30 40 do you want to see main menu?(y/n)n Result: Thus the given program Queue ADT operations using Linked List was executed successfully.insert 2.display enter your choice 2 the deleted element is 10 do you want main menu?(y/n) y program for queue using linked list main menu 1.www. delete 3. delete 3.display enter your choice 3 the display of queue is 10 20 30 40 do you want main menu?(y/n) y program for queue using linked list main menu 1.rejinpaul.com 3.Vidyarthiplus. www.insert 2. delete 3.com www.display enter your choice 2 the deleted element is 20 do you want main menu?(y/n) y program for queue using linked list main menu 1.com www.insert 2.com 41 .

rejinpaul.delete 4. Program: Output: program for binary search tree 1. Declare function create().com www. Create a structure for a tree contains left pointer and right pointer.delete(). 5. Algorithm: 1.display enter your choice 1 enter the element 10 do you want to enter more elements”(y/n) y enter the element 8 do you want to enter more elements”(y/n) y enter the element 7 do you want to enter more elements”(y/n) y enter the element 9 do you want to enter more elements”(y/n) y enter the element 12 do you want to enter more elements”(y/n) y enter the element 11 do you want to enter more elements”(y/n) www.com www.Vidyarthiplus. No:12 Aim: To write a c++ program for binary search tree. 3.rejinpaul.search(). 4.Display().create 2. Deleting an element contains searching the tree and deleting the item. Insert an element is by checking the top node and the leaf node and the operation will be performed.search 3. 2.com 42 .Vidyarthiplus.www. display the Tree elements.com BINARY SEARCH TREE Ex.

search 3.com www.create 2.display enter your choice 4 the tree is : 7 8 9 10 11 13 1.display enter your choice 3 enter the element you wish to delete 12 the 12 element is present now deleted it! 1.delete 4.com do you want to enter more elements”(y/n) n 1.rejinpaul.create 2.com y enter the element 13 www.delete 4.rejinpaul.www.display www.search 3.delete 4.search 3.create 2.com 43 .search 3.delete 4.display enter your choice 4 the tree is: 7 8 9 10 11 12 13 1.Vidyarthiplus.create 2.create 2.search 3.display enter your choice 2 enter the element which you want to search 13 the 13 element is present parent of node 13 is 12 1.Vidyarthiplus.delete 4.

create 2.com enter your choice 3 www.search 3.rejinpaul.delete 4.search 3.com 44 . www.create 2.search 3.Vidyarthiplus.create 2.display enter your choice 4 the tree is : 8 9 10 13 1.delete 4.delete 4.com www.display enter your choice 4 the tree is : 7 8 9 10 13 1.rejinpaul.create 2.Vidyarthiplus.com enter the element you wish to delete 11 the 11 element is present now deleted it! 1.display enter your choice 3 enter the element you wish to delete 7 the 7 element is present now deleted it! 1.www.display enter your choice 5 Result: Thus the given program Binary Search Tree was executed successfully.delete 4.search 3.

Get the elements to be sorted. Algorithm: 1. Get the size of the array from the user. 5. Now the array is contained with sorted elements.com HEAP SORT www. 4.rejinpaul.www. 3.Vidyarthiplus.com www.rejinpaul.com 45 . www. 2. No:1 Aim: To write a C++ program to perform heap sort.com Ex.Vidyarthiplus. Sorting is performed when we call the heap sort function. Display the sorted elements. 14 12 9 8 7 10 18 heapified 18 12 14 8 7 9 10 Elements sorted by heap sort 7 8 9 10 12 14 18 Result: Thus the given program Heap Sort was executed successfully. Program: Output: the elements are….

3. then recursively sorting each partition. www. Program: Output quick sort method enter total numbers to sort: 5 enter element 30 enter element 50 enter element 10 enter element 20 enter element 40 sorted array is 10 20 30 40 50 Result: Thus the given program quick sort was implemented successfully. Quick sort to perform sorting. to be sorted.Vidyarthiplus. Get the elements from the user.www.No :14 Aim: To write a c program to perform quick sort. 6.com www. Quick sort algorithm works by partitioning the array to be sorted. 2.rejinpaul. Algorithm: 1.com www. Get the value of how many no. 5.rejinpaul. Swap() is just to rearrange the values. 4.com QUICK SORT Ex. Two function quicksort() and swap(). Display the sorted value.Vidyarthiplus.com 46 .

com Ex. 14 12 9 8 7 10 18 heapified 18 12 14 8 7 9 10 Elements sorted by heap sort 7 8 9 10 12 14 18 Result: Thus the given program Heap Sort was executed successfully. 2.com 47 . Display the sorted elements. 5. 4. Sorting is performed when we call the heap sort function. No: 15 HEAP SORT www.com Aim: To write a c program to perform heap sort.Vidyarthiplus.rejinpaul. 3. Get the size of the array from the user. Get the elements to be sorted. www.com www. Now the array is contained with sorted elements.rejinpaul.www. Program: Output: the elements are…. Algorithm: 1.Vidyarthiplus.