Sie sind auf Seite 1von 17

LAB MANUAL

Course Title: Data Structures Lab Course Code: 15IS305


Author: Ms. Manasa & Ms. Deepa Year: 2016-17

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.

2. LAB RULES AND REGULATIONS [REFER L1 FILE]

3. LIST OF PROGRAMS

1. Write a C program for the following operations on a stack of integers (use


arrays/structures).

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 +, -,/,*,^($).

4. Write a C program to check given a string is a palindrome or not using stack.

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

8. Write a c program to design a priority queue. 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
}

int pop(struct stack *s)


{
//Remove elements from the stack
}

void display(struct stack *s)


{
//Display the contents of stack
}
Test Cases:

1) Check for Underflow condition.


2) Check for Overflow condition.
3) Push 5 elements.
4) Pop 3 elements.

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

char stacktop(struct stack *s)


{
// Return top element
}

void push(struct stack *s,char c)


{
//Insert the elements
}

char pop(struct stack *s)


{
// Remove the elements
}

int empty(struct stack *s)


{
//Check for underflow condition
}

int prec(char stk,char in)


{
// Check the precedence.
}

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
}

float pop(struct stack *s)


{
//Removes element from stack
}
float oper(char c,float op1,float op2)
{
//Check for the precedence.
}

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 +

4. Write a C program to check given a string is a palindrome or not using stack.


Skeleton:
int main()
{
//Enter a string.
//Push the elements to stack
//Pop the elements from the stack
//Check if they are equal.
//Print the result.
}
void push(STACK *p, int element)
{
//Insert elements to the stack
}
int pop(STACK *p)
{
//Remove the elements from stack
}
void display(STACK s)
{
//Display the contents.
}
int isoverflow(int top)
{
//check stack overflow condition
}
int isempty(int top)
{
//check stack empty condition
}
Test Cases:
1. Check for malayalam
2. Check for box
3. Check for NMAMIT
4. Check for madam
5. Write a C program to simulate the working of a queue of integers using array. Provide the
following operations
v) Insert
vi) Delete
iii) Display
Display appropriate messages on Queue over flow and Queue under flow conditions.
Skeleton:

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:

1) Check for Underflow condition.


2) Check for Overflow condition.
3) Insert 4 elements.
4) Delete 2 elements.

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
}

void qdelete(struct queue *q)


{
//Delete an element from queue
}

void qdisplay(struct queue *q)


{
//Display the contents
}

Test Cases:

1) Check for Underflow condition.


2) Check for Overflow condition.
3) Insert 4 elements.
4) Delete 2 elements.

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
}

void cqdelete(struct cqueue *cq)


{
//Delete an item from circular queue
}
void cqdisplay(struct cqueue *cq)
{
//Display the elements of circular queue
}

Test Cases:

1. Check for QUEUE full condition.


2. Check for QUEUE Empty condition.
3. Insert the values 6, 40, and 28 into QUEUE
4. Check for deletion error.

8. Write a c program to design a priority queue. Provide the following operations:


i) Insert ii) Delete iii) Display
Skeleton:

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:

1. Try deleting an element which is not present.


2. Check for queue empty condition.
3. Try inserting same element with the same priority.
4. Try inserting different elements with the same priority.

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
}

void push(NODEPTR *list,int x)


{
//Insert an element into list
}
void pop(NODEPTR *list)
{
//Delete an element from list
}

int empty(NODEPTR *list)


{
//Ckeck for list empty
}

NODEPTR getnode()
{
//Create a node
}

void freenode(NODEPTR p)
{
//Free the node
}

void display(NODEPTR *list)


{
//Display the contents
}
Test Cases:

1. Check for character inputs.


2. Push 6 elements.
3. Display the Stack.
4. Pop 3 elements.

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
}

void insert( struct queue *q,int x)


{
//Insert an element into the linked list
}

void rem(struct queue *q)


{
//Delete an elemnt from the linked list
}

NODEPTR getnode( )
{
//Create a node
void freenode(NODEPTR p)
{
//Free the node
}
void display(struct queue *q)
{
//Display the contents

Test Cases:

1. Check for character inputs.


2. Insert 2 elements.
3. Display the Queue.
4. Delete 2 elements.

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

void insfront(NODEPTR *list,int x,char *y,int z)


{
//Insert an element in the beginining
}

void insend(NODEPTR *list,int x,char *y,int z)


{
//Insert an element at the end
}

NODEPTR getnode()
{
//Create a node
}

void freenode(NODEPTR p)
{
//Free the node

NODEPTR search(NODEPTR *list,int x)


{
//Search an item
}

void del(NODEPTR *list,int x)


{
//Delete an item
}

void deleteafter(NODEPTR p,int *px)


{
//Delete an item after a specified item
}

void display(NODEPTR li)


{
//Display the contents.
}

void insafter(NODEPTR p,int x,char *y,int z)


{
//Insert an item after a specified item
}

void ins(NODEPTR *list,int pos,int x,char *y,int z)


{
//Insert an item to a specific position
}

Test Cases:

1. Insert a student record with ID 10


2. Search for a student record with ID 3
3. Delete a student record
4. Display the records.

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

void insert(NODEPTR *list,int x)


{
//Insert an element
}

void insleft(NODEPTR *list,int x)


{
// Left insertion
}

void deleft(NODEPTR *list,int ele)


{
//Left deletion
}

void display(NODEPTR *list)


{
//Display the contents.
}
NODEPTR getnode()
{
//Create a node
}
void freenode(NODEPTR p)
{
//Free the node
}
Test Cases:
1. Insert 20
2. Insert 19 before 20
3. Delete 19
4. 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:

struct node* createNode(int data) {


//Create a node
}

void insertNode(int data) {


//insert into a circular linked list

void deleteNode(int data) {

//delete from a circular linked list

void display() {

//Display the contents

int main() {

//Call insert function


//Call delete function
//Call display function

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

//Call maketree function


//Call inorder function
//Call preorder function
//Call postorder function
}

NODEPTR maketree(int x)
{
//create a tree
}

void setleft(NODEPTR p,int x)


{
//insert element into left subtree
}

void setright(NODEPTR p,int x)


{
//insert element into right subtree
}

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

5. SAMPLE VIVA QUESTIONS.


1) What is Stack?
2) Explain various operations on stack.
3) Explain exception conditions in stack.
4) What is infix expression?
5) What is postfix expression?
6) Explain the algorithm which converts infix expression to postfix expression.
7) What is postfix expression.
8) Explain the precedence rules.
9) Explain the algorithm which evaluates postfix expression.
10) What is a palindrome?Explain the logic to reverse a string
11) How this logic is implemented using stacks?
12)What is Queue?
13) Explain various operations on queue.
14) Explain exception conditions in queue.
15) Check for QUEUE full condition.
16) Check for QUEUE Empty condition.
17) Insert the values 6, 40, and 28 into QUEUE
18) Check for deletion error.
19) What is Priority Queue?
20) How PQ is different from ordinary queue?
21) Explain the logic of Priority Queue.1. What is a linked list?
22) What is dynamic memory allocation?
23) What is singly linked list?
24) What is a linked list?
25) Explain qempty condition.
26) Explain how do you insert an item into the list
27) How to search an item?
28) How to insert an item after a specified item?
29) How to insert an item to a specific position.
30) What is a doubly linked list?
31) How to delete an item from the left?
32) How to insert an item to left?
33) What is circular doubly linked list?
34) How is circular doubly linked list different from doubly linked list?
35) Explain the logic of inserting a node
36) What is a binary tree?
37) What is inorder traversal?
38) What is postorder traversal?

6. EVALUATION CRITERIA

6.1 CONTINUOUS EVALUATION: 20 MARKS

Work done in each lab 10 Marks


Viva 10 Marks
Total 20 marks

6.2 MSE: 30 MARKS

Excluding Challenging Challenging Programs


Programs
Write up 05 Marks 05 Marks
Part A 05 Marks 05 Marks
Part B 10 Marks 15 Marks
Viva 05 Marks 05 Marks
Total 25 Marks 30 Marks

6.3 SEE: 50 MARKS

Excluding Challenging Challenging Programs


Programs
Write up 05 Marks 05 Marks
Part A 10 Marks 10 Marks
Part B 15 Marks 25 Marks
Viva 10 Marks 10 Marks
Total 40 Marks 50 Marks

Das könnte Ihnen auch gefallen