Beruflich Dokumente
Kultur Dokumente
1. INTRODUCTION
This lab requires the student to know C/C++ Programming Language and Data
Structures Theory. In this lab students will learn the fundamental of Data Structures and
its working with specific algorithms using Data Structures. This lab focuses on
developing programming skills about designing and implementation of Data Structures
and their applications.
3. LIST OF PROGRAMS
a) Push
b) Pop
c) Display
The program should print appropriate messages for stack overflow and stack underflow.
2. Write a C program to convert and print a given valid parenthesized infix arithmetic
expression to postfix expression. The expression consists of single character operands and +,-
, *, / operators.
3.Write a C program to evaluate a valid suffix/postfix expression using stack. Assume that
suffix/postfix expression is read as a single line consisting of non negative single digit
operands and binary arithmetic operators. The arithmetic operators are +, -,/,*,^($).
5. Write a C program to simulate the working of a queue of integers using arrays. Provide the
following operations
i) Insert
ii) Delete
iii) Display
Display appropriate messages on Queue overflow and Queue underflow conditions.
6. Write a C program to simulate the working of a queue of integers using structures. Provide
the following operations
iii) Insert
iv) Delete
iii) Display
Display appropriate messages on Queue overflow and Queue underflow conditions.
7. Write a C program to simulate the working of a circular queue of integers using array or
structure. Provide the following operations.
i) Insert ii) Delete iii) Display
9. Write C program using dynamic variables and pointers to construct a Singly Linked List to
perform the operations on a stack of integers. (Push, Pop, Display)
10. Write C program using dynamic variables and pointers to construct a Singly Linked list
to perform the operations on a queue of integers.
11. Write a C program using dynamic variables and pointers to construct a Singly Linked
List consisting of the following information in each node: student id (integer), student name
(character string) and semester (integer). The operations to be supported are:
i) Insert rear
ii) Insert at front
iii) Insert at specified position
iv) Delete a student with a given id
v) Search for an id.
vi) Display the nodes in the list
12. Write a C program to support the following operations on a Doubly Linked List where
each node consists of integers.
i) Insert front ii) Delete rear iii) Display.
13. Write a C program to support the following operations on a Circular Doubly Linked
List where each node consists of integers.
i) Insert ii) Delete iii) Display.
14. Write a C program to implement a Binary Search Tree of integers and perform the
following traversal techniques: i)In-order traversal ii)Post-order traversal iii)Pre-order
traversal.
4. SOLUTIONS
1. Write a C program for the following operations on a stack of integers using
arrays/structures.
a) Push
b) Pop
c) Display
The program should print appropriate messages for stack overflow and stack underflow
Skeleton:
void main()
{
// Use Switch statements to call the functions and display the menu.
// Call push function
//Call pop function
//Call display function
}
void push(struct stack *s,int a)
{
//Add elements to the stack
}
2. Write a C program to convert and print a given valid parenthesized infix arithmetic
expression to postfix expression. The expression consists of single character operands and +,-
, *, / operators.
void main()
{
// Read infix expression
//Call below mentioned functions to convert infix expression to postfix.
// Print postfix expression.
}
Test Cases:
1. Check for A*(B+C)/D
2. Check for (E * (F + (G / H) ) )
3. Check for ((I + (J * K)) + L)
4. Check for M * N + O * P
3. Write a C program to evaluate a valid suffix/postfix expression using stack. Assume that
suffix/postfix expression is read as a single line consisting of non –negative single digit
operands and binary arithmetic operators. The arithmetic operators are The arithmetic
operators are +, -,/,*,^($)****************/
Skeleton:
void main()
{
// Read the postfix expression
//Call below mentioned functions to evaluate the postfix expression.
// Print the result
}
void push(struct stack *s,float a)
{
//Inserts element into stack
}
Test Cases:
1. Check for 20 30 +
2. Check for 10 12 + 3 4 – +
3. Check for 5 1 2 + 4 * + 3 -
4. Check for 1 2 * 3 +
void main()
{
Use Switch statements to call the functions and display the menu.
// Call insert function
//Call delete function
//Call display function
}
void insert()
{
//Inserts an element into queue
}
void del()
{
//Delete an elemnt from the queue
}
void display()
{
//Display the contents of queue
}
Test Cases:
6. Write a C program to simulate the working of a queue of integers using structure. Provide
the following operations
vii) Insert
viii) Delete
iii) Display
Display appropriate messages on Queue over flow and Queue under flow conditions.
Skeleton
void main()
{ //Call qinsert function.
//Call qdelete function.
//Call display function.
}
void qinsert(struct queue *q,int n)
{
//Insert an element into queue
}
Test Cases:
7. Write a C program to simulate the working of a circular queue of integers using array or
structure. Provide the following operations
i) Insert ii) Delete iii) Display
Skeleton:
void main()
{
//Call cqinsert function
//Call cqdelete function
//Call cqdisplay function
}
void cqinsert(struct cqueue *cq,int x)
{
//Insert an item into circular queue
}
Test Cases:
void insert(struct node **front, struct node **rear, int value, int priority)
{
//Insert an element into circular queue
}
void delete(struct node **front, struct node **rear, int *value, int *priority)
{
//Delete an element from priority queue
}
void main()
{
//Call insert function.
//Call delete function
//
}
Test Cases:
9. Write C program using dynamic variables and pointers to construct a singly Linked list to
perform the operations of a stack of integers. (Push, Pop, Display)
Skeleton
void main()
{
//Call push function
//Call pop function
//Call display function
}
NODEPTR getnode()
{
//Create a node
}
void freenode(NODEPTR p)
{
//Free the node
}
10. Write C program using dynamic variables and pointers to construct a singly Linked list to
perform the operations of a queue of integers.
Skeleton:
void main()
{
//Call insert function
//Call rem function
//Call display function
}
NODEPTR getnode( )
{
//Create a node
void freenode(NODEPTR p)
{
//Free the node
}
void display(struct queue *q)
{
//Display the contents
Test Cases:
11. Write a C program using dynamic variables and pointers to construct a singly linked list
consisting of the following information in each node: student id (integer), student name
(character string) and semester (integer). The operations to be supported are:
i) Insert rear
ii) Insert at front
iii) Insert at specified position
iv) Delete a student with a given id
v) Search for an id.
vi) Display the nodes in the list
Skeleton:
void main()
{
//Call insfront function
//Call insend function
//Call search function
//Call del function
//Call deleteafter function
//Call insafter function
//Call display function
NODEPTR getnode()
{
//Create a node
}
void freenode(NODEPTR p)
{
//Free the node
Test Cases:
12. Write a C program to support the following operations on a doubly linked list where each
node consists of integers.
i) insert right ii) Insert before any element iii) Delete an element and iv) Display
Skeleton:
void main()
{
//Call insert function
//Call insleft
//Call deleft
//Call display
13. Write a C program to support the following operations on a Circular Doubly Linked List
where each node consists of integers.
i) Insert ii) Delete iii) Display.
Skeleton:
void display() {
int main() {
Test Cases:
1. Insert 68
2. Delete 2
3. Display List
4. Try inserting 1.2
14. Write a C program to implement a binary search tree of integers and perform the
following traversal techniques: i) In-order traversal ii)Post-order traversal iii)Pre-order
traversal
Skeleton:
void main()
{
NODEPTR maketree(int x)
{
//create a tree
}
void inorder(NODEPTR p)
{
//inorder traversal
}
void postorder(NODEPTR p)
{
//postorder traversal
}
void preorder(NODEPTR p)
{
//Preorder traversal
}
NODEPTR getnode()
{
//Create a node
}
Test Cases:
1. Insert 1, 5, 6, 8, 3, 9
2. Traverse the given input in Inorder
3. Traverse the given input in Preorder
4. Traverse the given input in Postorder
6. EVALUATION CRITERIA