Data Structures Lab Record-1
Data Structures Lab Record-1
LABORATORY RECORD
U21CSG03
DATA STRUCTURES LABORATORY
KPR INSTITUTE OF ENGINEERING AND TECHNOLOGY
(Autonomous) COIMBATORE – 641 407
LABORATORY RECORD
Name : ……………………………………………………………….
Department : ……………………………………………………………….
Register Number………………………………………………………
Place:
Date:
He/ She has submitted the record for the End Semester
PracticalExamination held on ……………………
2
VISION AND MISSION OF THE INSTITUTION
Vision
To become a premier institute of academic excellence by imparting technical, intellectual and
professional skills to students for meeting the diverse need of the industry, society, the nation and the
world at large
Mission
Commitment to offer value-based education and enhancement of practical skills
Continuous assessment of teaching and learning process through scholarly activities
Enriching research and innovation activities in collaboration with industry and institute of repute
Ensuring the academic process to uphold culture, ethics and social responsibility
4
RUBRICS FOR ASSESSMENT
contingency or theoretical
Criterion #1 Able to develop framework,
alternative plans framework,
Ability to setup contingency or measurement
and anticipate measurement
and conduct alternative plans. techniques,
problems during techniques, testing
experiments testing apparatus
experiment. apparatus or model.
or model.
Able to formulate,
controls and Able to apply
Criterion #2 evaluate constraint and
Able to evaluate
Ability to take alternatives of the assumption into the Unable to discuss
data and relate to
measurements experiment. Able to experimental experimental
engineering
/ readings and evaluate data and design. Able to processes and
phenomena for
present data relate to conduct experiment protocols
decision-making.
engineering correctly and collect
phenomena for data.
decision-making.
Criterion #3
Ability to
Able to combine Able to select and Unable to select
analyze the
B. Results & Interpretation
/organize more than Able to evaluate or use and apply and describe the
data
one set of data, compare data and appropriate techniques or
theoretically
interpret data and make meaningful techniques or methods of
and logically to
make meaningful conclusion methods to analyse analyzing the
conclude
conclusion. the data. data.
experimental
results
Criterion #4
Ability to
Able to verify and/or Able to verify and/or
interpret and Able to identify and Unable to identify
validate several sets validate data and
discuss any verify how results how results
of data and relates relate to
discrepancies relate/differ from relate/differ from
to engineering engineering
between theory or previous theory or previous
phenomena for phenomena for
theoretical and results results.
decision making. decision making.
experimental
results
Able to listen Misunderstand the Unable to listen
C. Viva Voce
5
INDEX
Page
Ex. No. Date Experiment Name No. Marks Signature
3
Choose an appropriate data structure and create
a token system for banking service (withdrawal,
9 deposit, and money transfer).
Average(A) /20
4
Ex. No.: 1 SINGLY LINKED LIST
Date:
AIM
To write a function program to perform the following operations on a singly linked list
i. Create a list cube.
ii. Insert an element to the list
iii. Delete the maximum element from the list
iv. Arrange the list as sorted order
v. Display the elements of the list
ALGORITHM
PROGRAM
8
printf("3 : Display Linked List\n");
printf("4 : Count Linked List\n");
printf("Others : Exit()\n");
printf("Enter your option:");
scanf("%d", &option);
switch (option) {
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
count();
break;
default:
break;
}
}
return 0;
}
void insert() {
printf("\nEnter Element for Insert Linked List : \n");
scanf("%d", &data);
temp_node = (DATA_NODE *) malloc(sizeof (DATA_NODE));
temp_node->value = data;
if (first_node == 0) {
first_node = temp_node;
}
else {
head_node->next = temp_node;
}
temp_node->next = 0;
head_node = temp_node;
fflush(stdin);
}
void delete() {
int countvalue, pos, i = 0;
countvalue = count();
temp_node = first_node;
printf("\nDisplay Linked List : \n");
printf("\nEnter Position for Delete Element : \n");
scanf("%d", &pos);
if (pos > 0 && pos <= countvalue) {
9
if (pos == 1) {
temp_node = temp_node -> next;
first_node = temp_node;
printf("\nDeleted Successfully \n\n");
}
else {
while (temp_node != 0) {
if (i == (pos - 1)) {
prev_node->next=temp_node->next;
if(i == (countvalue - 1)){
head_node = prev_node;
}
printf("\nDeleted\n\n");
break;
}
else {
i++;
prev_node = temp_node;
temp_node = temp_node -> next;
}
}
}
}
else{
printf("\nInvalid Position \n\n");
}
void display() {
int count = 0;
temp_node = first_node;
printf("\nDisplay Linked List : \n");
while (temp_node != 0) {
printf("# %d # ", temp_node->value);
count++;
temp_node = temp_node -> next;
}
printf("\nNo Of Items In Linked List : %d\n", count);
}
int count() {
int count = 0;
temp_node = first_node;
while (temp_node != 0) {
count++;
temp_node = temp_node -> next;
}
printf("\nNo Of Items In Linked List : %d\n", count);
return count;
10
}
OUTPUT:
Criteria Score
RESULT
Thus to write a function program to perform the following operations on a singly
linked list was executed and output was verified successfully.
13
Ex. No.: 2 STACK AND QUEUE ADTS
Date:
AIM
To Create an Array and linked list implementation using Stack and Queue ADTs.
ALGORITHM
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
struct node
{
int info;
struct node *ptr;
}*top,*top1,*temp;
int topelement();
void push(int data);
void pop();
void empty();
void display();
void destroy();
void stack_count();
void create();
int count = 0;
void main()
{
int no, ch, e;
printf("\n 1 - Push");
printf("\n 2 - Pop");
printf("\n 3 - Top");
printf("\n 4 - Empty");
printf("\n 5 - Exit");
printf("\n 6 - Dipslay");
printf("\n 7 - Stack Count");
printf("\n 8 - Destroy stack");
14
create();
while (1)
{
printf("\n Enter choice : ");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("Enter data : ");
scanf("%d", &no);
push(no);
break;
case 2:
pop();
break;
case 3:
if (top == NULL){
printf("No elements in stack");
}
else
{
e = topelement();
printf("\n Top element : %d", e);
}
break;
case 4:
empty();
break;
case 5:
exit(0);
case 6:
display();
break;
case 7:
stack_count();
break;
case 8:
destroy();
break;
default :
printf(" Wrong choice, Please enter correct choice ");
break;
}
}
}
/* Create empty stack */
15
void create()
{
top = NULL;
}
/* Count stack elements */
void stack_count()
{
printf("\n No. of elements in stack : %d", count);
}
/* Push data into stack */
void push(int data)
{
if (top == NULL)
{
top =(struct node *)malloc(1*sizeof(struct node));
top->ptr = NULL;
top->info = data;
}
else
{
temp =(struct node *)malloc(1*sizeof(struct node));
temp->ptr = top;
temp->info = data;
top = temp;
}
count++;
}
/* Display stack elements */
void display()
{
top1 = top;
if (top1 == NULL)
{
printf("Stack is empty");
return;
}
while (top1 != NULL)
{
printf("%d ", top1->info);
top1 = top1->ptr;
}
}
/* Pop Operation on stack */
void pop()
{
top1 = top;
16
if (top1 == NULL)
{
printf("\n Error : Trying to pop from empty stack");
return;
}
else{
top1 = top1->ptr;
printf("\n Popped value : %d", top->info);
free(top);
}
top = top1;
count--;
}
/* Return top element */
int topelement()
{
return(top->info);
}
/* Check if stack is empty or not */
void empty()
{
if (top == NULL)
printf("\n Stack is empty");
else
printf("\n Stack is not empty with %d elements", count);
}
/* Destroy entire stack */
void destroy()
{
top1 = top;
while (top1 != NULL)
{
top1 = top->ptr;
free(top);
top = top1;
top1 = top1->ptr;
}
free(top1);
top = NULL;
printf("\n All stack elements destroyed");
count = 0;
}
OUTPUT
$ cc pgm2.c
$ a.out
1 - Push
17
2 - Pop
3 - Top
4 - Empty
5 - Exit
6 - Dipslay
18
7 - Stack Count
8 - Destroy stack
Enter choice : 1
Enter data : 56
Enter choice : 1
Enter data : 80
Enter choice : 2
Popped value : 80
Enter choice : 3
Top element : 56
Enter choice : 1
Enter data : 78
Enter choice : 1
Enter data : 90
Enter choice : 6
90 78 56
Enter choice : 7
No. of elements in stack : 3
Enter choice : 8
All stack elements destroyed
Enter choice : 4
Stack is empty
Enter choice : 5
#include <stdio.h>
#include <stdlib.h>
struct node
{
int info;
struct node *ptr;
}*front,*rear,*temp,*front1;
int frontelement();
void enq(int data);
void deq();
void empty();
void display();
void create();
void queuesize();
int count = 0;
void main()
18
{
int no, ch, e;
printf("\n 1 - Enque");
printf("\n 2 - Deque");
printf("\n 3 - Front element");
printf("\n 4 - Empty");
printf("\n 5 - Exit");
printf("\n 6 - Display");
printf("\n 7 - Queue size");
create();
while (1)
{
printf("\n Enter choice : ");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("Enter data : ");
scanf("%d", &no);
enq(no);
break;
case 2:
deq();
break;
case 3:
e = frontelement();
if (e != 0)
printf("Front element : %d", e);
else
printf("\n No front element in Queue as queue is empty");
break;
case 4:
empty();
break;
case 5:
exit(0);
case 6:
display();
break;
case 7:
queuesize();
break;
default:
printf("Wrong choice, Please enter correct choice ");
break;
}
}
}
19
/* Create an empty queue */
void create()
{
front = rear = NULL;
}
/* Returns queue size */
void queuesize()
{
printf("\n Queue size : %d", count);
}
/* Enqueing the queue */
void enq(int data)
{
if (rear == NULL)
{
rear = (struct node *)malloc(1*sizeof(struct node));
rear->ptr = NULL;
rear->info = data;
front = rear;
}
else
{
temp=(struct node *)malloc(1*sizeof(struct node));
rear->ptr = temp;
temp->info = data;
temp->ptr = NULL;
rear = temp;
}
count++;
}
/* Displaying the queue elements */
void display()
{
front1 = front;
if ((front1 == NULL) && (rear == NULL))
{
printf("Queue is empty");
return;
}
while (front1 != rear)
{
printf("%d ", front1->info);
front1 = front1->ptr;
}
if (front1 == rear)
printf("%d", front1->info);
}
/* Dequeing the queue */
20
void deq()
{
front1 = front;
if (front1 == NULL)
{
printf("\n Error: Trying to display elements from empty queue");
return;
}
else
if (front1->ptr != NULL)
{
front1 = front1->ptr;
printf("\n Dequed value : %d", front->info);
free(front);
front = front1;
}
else
{
printf("\n Dequed value : %d", front->info);
free(front);
front = NULL;
rear = NULL;
}
count--;
}
/* Returns the front element of queue */
int frontelement()
{
if ((front != NULL) && (rear != NULL))
return(front->info);
else
return 0;
}
/* Display if queue is empty or not */
void empty()
{
if ((front == NULL) && (rear == NULL))
printf("\n Queue empty");
else
printf("Queue not empty");
}
OUTPUT
$ cc pgm4.c
$ a.out
1 - Enque
2 - Deque
21
3 - Front element
4 - Empty
5 - Exit
6 - Display
7 - Queue size
Enter choice : 1
Enter data : 14
Enter choice : 1
Enter data : 85
Enter choice : 1
Enter data : 38
Enter choice : 3
Front element : 14
Enter choice : 6
14 85 38
Enter choice : 7
Queue size : 3
Enter choice : 2
Dequed value : 14
Enter choice : 6
85 38
Enter choice : 7
Queue size : 2
Enter choice : 4
Queue not empty
Enter choice : 5
Criteria Score
RESULT
Thus the program to Creation of Array and linked list implementation of Stack and Queue
ADTs was executed and output was verified successfully.
22
Ex. No.: 3 IMPLEMENTATION OF QUICK, HEAP AND SHELL SORT
Date:
AIM
To Create an Array and linked list implementation using Stack and Queue ADTs.
ALGORITHM
PROGRAM:
i. Quick sort
#include<stdio.h>
void quicksort(int number[25],int first,int last){
int i, j, pivot, temp;
if(first<last){
pivot=first;
i=first;
j=last;
while(i<j){
while(number[i]<=number[pivot]&&i<last)
i++;
while(number[j]>number[pivot])
j--;
if(i<j){
temp=number[i];
number[i]=number[j];
number[j]=temp;
}
}
temp=number[pivot];
number[pivot]=number[j];
number[j]=temp;
quicksort(number,first,j-1);
quicksort(number,j+1,last);
}
}
int main(){
int i, count, number[25];
printf("How many elements are u going to enter?: ");
scanf("%d",&count);
printf("Enter %d elements: ", count);
23
for(i=0;i<count;i++)
scanf("%d",&number[i]);
quicksort(number,0,count-1);
printf("Order of Sorted elements: ");
for(i=0;i<count;i++)
printf(" %d",number[i]);
return 0;
}
OUTPUT
#include <stdio.h>
/* function to heapify a subtree. Here 'i' is the
index of root node in array a[], and 'n' is the size of heap.*/
void heapify(int a[], int n, int i)
{
int largest = i; // Initialize largest as root
int left = 2 * i + 1; // left child
int right = 2 * i + 2; // right child
// If left child is larger than root
if (left < n && a[left] > a[largest])
largest = left;
// If right child is larger than root
if (right < n && a[right] > a[largest])
largest = right;
// If root is not largest
if (largest != i) {
// swap a[i] with a[largest]
int temp = a[i];
a[i] = a[largest];
a[largest] = temp;
heapify(a, n, largest);
}
}
/*Function to implement the heap sort*/
void heapSort(int a[], int n)
{
for (int i = n / 2 - 1; i >= 0; i--)
heapify(a, n, i);
// One by one extract an element from heap
for (int i = n - 1; i >= 0; i--) {
/* Move current root element to end*/
24
// swap a[0] with a[i]
int temp = a[0];
a[0] = a[i];
a[i] = temp;
heapify(a, i, 0);
}
}
/* function to print the array elements */
void printArr(int arr[], int n)
{
for (int i = 0; i < n; ++i)
{
printf("%d", arr[i]);
printf(" ");
}
}
int main()
{
int a[] = {48, 10, 23, 43, 28, 26, 1};
int n = sizeof(a) / sizeof(a[0]);
printf("Before sorting array elements are - \n");
printArr(a, n);
heapSort(a, n);
printf("\nAfter sorting array elements are - \n");
printArr(a, n);
return 0;
}
OUTPUT
Before Sorting the array elements are
48 10 23 43 28 26 1
After Sorting the array elements are
1 10 23 26 28 43 48
#include <stdio.h>
void shellsort(int arr[], int num)
{
int i, j, k, tmp;
for (i = num / 2; i > 0; i = i / 2)
{
for (j = i; j < num; j++)
{
for(k = j - i; k >= 0; k = k - i)
{
if (arr[k+i] >= arr[k])
break;
25
else
{
tmp = arr[k];
arr[k] = arr[k+i];
arr[k+i] = tmp;
}
}
}
}
}
int main()
{
int arr[30];
int k, num;
printf("Enter total no. of elements : ");
scanf("%d", &num);
printf("\nEnter %d numbers: ", num);
for (k = 0 ; k < num; k++)
{
scanf("%d", &arr[k]);
}
shellsort(arr, num);
printf("\n Sorted array is: ");
for (k = 0; k < num; k++)
printf("%d ", arr[k]);
return;
}
Criteria Score
RESULT
Thus, the program to Implement quick, heap and shell sort was executed and output
was verified successfully.
26
Ex. No.: 4 SELECTION SORT AND BUBBLE SORT
Date:
AIM
To develop a c program to sort the elements in ascending order using selection sort and
bubble sort.
ALGORITHM
PROGRAM
i. Selection Sort
#include <stdio.h>
int main()
{
int a[100], n, i, j, position, swap;
printf("Enter number of elementsn");
scanf("%d", &n);
printf("Enter %d Numbersn", n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for(i = 0; i < n - 1; i++)
{
position=i;
for(j = i + 1; j < n; j++)
{
if(a[position] > a[j])
position=j;
}
if(position != i)
{
swap=a[i];
a[i]=a[position];
a[position=swap;
}
}
printf("Sorted Array:n");
for(i = 0; i < n; i++)
printf("%dn", a[i]);
return 0;
}
27
OUTPUT
ii.Bubble sort
#include <stdio.h>
int main() {
int array[100], n, c, d, swap;
printf("Enter number of elements\n"); scanf("%d", &n);
printf("Enter %d integers\n", n);
for (c = 0; c < n; c++) scanf("%d", &array[c]);
for (c = 0 ; c < n - 1; c++) {
for (d = 0 ; d < n - c - 1; d++) {
if (array[d] > array[d+1])
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}
printf("Sorted list in ascending order:\n");
for (c = 0; c < n; c++)
printf("%d\n", array[c]);
return 0;
}
OUTPUT
28
Criteria Score
RESULT
Thus to Program to sort the elements in ascending order using selection sort and
bubble sort was executed and output was verified successfully.
29
Ex. No.: 5 IMPLEMENTATION OF HASHING TECHNIQUE
Date:
AIM
ALGORITHM
Step :1 Create a List and using hashing function that maps a given value with
a key
Step :2 Display the elements
Step :3 Searching any elements using hashing function
Step :4 Display the searching elements
PROGRAM
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define SIZE 20
struct DataItem {
int data;
int key;
};
struct DataItem* hashArray[SIZE];
struct DataItem* dummyItem;
struct DataItem* item;
int hashCode(int key) {
return key % SIZE;
}
struct DataItem *search(int key) {
//get the hash
int hashIndex = hashCode(key);
//move in array until an empty
while(hashArray[hashIndex] != NULL) {
if(hashArray[hashIndex]->key == key)
return hashArray[hashIndex];
//go to next cell
++hashIndex;
//wrap around the table
hashIndex %= SIZE;
}
return NULL;
}
30
void insert(int key,int data) {
struct DataItem*item = (structDataItem*) malloc (sizeof (struct DataItem));
item->data = data;
item->key = key;
//get the hash
int hashIndex = hashCode(key);
//move in array until an empty or deleted cell
while(hashArray[hashIndex]!=NULL && hashArray[hashIndex]->key != -1) {
//go to next cell
++hashIndex;
//wrap around the table
hashIndex %= SIZE;
}
hashArray[hashIndex] = item;
}
struct DataItem* delete(struct DataItem* item) {
int key = item->key;
//get the hash
int hashIndex = hashCode(key);
//move in array until an empty
while(hashArray[hashIndex] != NULL) {
if(hashArray[hashIndex]->key == key) {
struct DataItem* temp = hashArray[hashIndex];
//assign a dummy item at deleted position
hashArray[hashIndex] = dummyItem;
return temp;
}
//go to next cell
++hashIndex;
//wrap around the table
hashIndex %= SIZE;
}
return NULL;
}
void display() {
int i = 0;
for(i = 0; i<SIZE; i++) {
if(hashArray[i] != NULL)
printf("(%d,%d)",hashArray[i]>key,hashArray[i]->data);
else
printf(" ~~ ");
}
printf("\n");
}
int main() {
31
dummyItem = (struct DataItem*) malloc(sizeof(struct DataItem));
dummyItem->data = -1;
dummyItem->key = -1;
insert(1, 20);
insert(2, 70);
insert(42, 80);
insert(4, 25);
insert(12, 44);
insert(14, 32);
insert(17, 11);
insert(13, 78);
insert(37, 97);
display();
item = search(37);
if(item != NULL) {
printf("Element found: %d\n", item->data);
}
else {
printf("Element not found\n");
}
delete(item);
item = search(37);
if(item != NULL) {
printf("Element found: %d\n", item->data);
}
else {
printf("Element not found\n");
}
}
OUTPUT
~~ (1,20) (2,70) (42,80) (4,25) ~~ ~~ ~~ ~~ ~~ ~~ ~~ (12,44) (13,78) (14,32) ~~ ~~ (17,11)
(37,97) ~~
Element found: 97
Element not found
32
Criteria Score
RESULT
Thus the implementation of hashing technique was executed and output was
verified successfully.
33
Ex. No.: 6 DEVELOP A PROGRAM TO PERFORM LINEAR AND BINARY SEARCH
Date:
AIM
ALGORITHM
PROGRAM
i. Linear search
#include <stdio.h>
int main() {
int array[100], search, c, n;
printf("Enter number of elements in array\n");
scanf("%d", &n);
printf("Enter %d integer(s)\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
printf("Enter a number to search\n");
scanf("%d", &search);
for (c = 0; c < n; c++) {
if (array[c] == search){
printf("%d is present at location %d.\n", search, c+1);
break;
}
}
if (c == n)
printf("%d isn't present in the array.\n", search);
return 0;
}
OUTPUT
34
ii.Binary search
#include <stdio.h>
int binarySearch(int array[], int x, int low, int high) {
// Repeat until the pointers low and high meet each other
while (low <= high) {
int mid = low + (high - low) / 2;
if (array[mid] == x)
return mid;
if (array[mid] < x)
low = mid + 1;
else
high = mid - 1;
}
return -1;
}
int main(void) {
int array[] = {3, 4, 5, 6, 7, 8, 9};
int n = sizeof(array) / sizeof(array[0]);
int x = 4;
int result = binarySearch(array, x, 0, n - 1);
if (result == -1)
printf("Not found");
else
printf("Element is found at index %d", result);
return 0;
}
OUTPUT
35
Criteria Score
RESULT
Thus, to write Develop a program to perform linear and binary search was
executed and output was verified successfully.
36
Ex. No.: 7 TREE TRAVERSAL METHODS
Date:
AIM
To write a C program to construct an expression tree for a given expression and perform
various tree traversal methods
ALGORITHM
PROGRAM
37
printPostorder(node->right);
// now deal with the node
printf("%d ", node->data);
}
/* Given a binary tree, print its nodes in inorder*/
void printInorder(struct node* node)
{
if (node == NULL)
return;
/* first recur on left child */
printInorder(node->left);
/* then print the data of node */
printf("%d ", node->data);
/* now recur on right child */
printInorder(node->right);
}
/* Given a binary tree, print its nodes in preorder*/
void printPreorder(struct node* node)
{
if (node == NULL)
return;
/* first print data of node */
printf("%d ", node->data);
/* then recur on left subtree */
printPreorder(node->left);
/* now recur on right subtree */
printPreorder(node->right);
}
/* Driver program to test above functions*/
int main()
{
struct node* root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
printf("\nPreorder traversal of binary tree is \n");
printPreorder(root);
printf("\nInorder traversal of binary tree is \n");
printInorder(root);
printf("\nPostorder traversal of binary tree is \n");
printPostorder(root);
getchar();
return 0;
}
38
OUTPUT
Criteria Score
RESULT
39
Ex. No.: 8 IMPLEMENTATION OF PRIMS ALGORITHM
Date:
AIM
ALGORITHM
PROGRAM
#include <stdio.h>
#include <limits.h>
#define vertices 5 /*Define the number of vertices in the graph*/
/* create minimum_key() method for finding the vertex that has minimum key-value and
that is not added in MST yet */
41
OUTPUT
Criteria Score
RESULT
Thus the program to Implement Prims algorithm was executed and output was
verified successfully.
42
Ex. No.: 9 TOKEN SYSTEM FOR BANKING SERVICE
Date:
AIM
To choose an appropriate data structure and create a token system for banking service
(withdrawal, deposit and money transfer
ALGORITHM
PROGRAM
#include <stdio.h>
struct customer
{
int account_no;
char name[80];
int balance;
};
void accept(struct customer[], int);
void display(struct customer[], int);
int search(struct customer[], int, int);
void deposit(struct customer[], int, int, int);
void withdraw(struct customer[], int, int, int);
int main()
{
struct customer data[20];
int n, choice, account_no, amount, index;
printf("Banking System\n\n");
printf("Number of customer records you want to enter? : ");
scanf("%d", &n);
accept(data, n);
do
{
printf("\nBanking System Menu :\n");
printf("Press 1 to display all records.\n");
printf("Press 2 to search a record.\n");
printf("Press 3 to deposit amount.\n");
printf("Press 4 to withdraw amount.\n");
printf("Press 0 to exit\n");
printf("\nEnter choice(0-4) : ");
scanf("%d", &choice);
43
switch (choice)
{
case 1:
display(data, n);
break;
case 2:
printf("Enter account number to search : ");
scanf("%d", &account_no);
index = search(data, n, account_no);
if (index == - 1)
{
printf("Record not found : ");
}
else
{
printf("A/c Number: %d\nName: %s\nBalance: %d\n",
data[index].account_no, data[index].name,
data[index].balance);
}
break;
case 3:
printf("Enter account number : ");
scanf("%d", &account_no);
printf("Enter amount to deposit : ");
scanf("%d", &amount);
deposit(data, n, account_no, amount);
break;
case 4:
printf("Enter account number : ");
scanf("%d", &account_no);
printf("Enter amount to withdraw : ");
scanf("%d", &amount);
withdraw(data, n, account_no, amount);
}
}
while (choice != 0);
return 0;
}
void accept(struct customer list[80], int s)
{
int i;
for (i = 0; i < s; i++)
{
printf("\nEnter data for Record #%d", i + 1);
printf("\nEnter account_no : ");
scanf("%d", &list[i].account_no);
fflush(stdin);
printf("Enter name : ");
44
gets(list[i].name);
list[i].balance = 0;
}
}
void display(struct customer list[80], int s)
{
int i;
printf("\n\nA/c No\tName\tBalance\n");
for (i = 0; i < s; i++)
{
printf("%d\t%s\t%d\n", list[i].account_no, list[i].name,
list[i].balance);
}
}
int search(struct customer list[80], int s, int number)
{
int i;
for (i = 0; i < s; i++)
{
if (list[i].account_no == number)
{
return i;
}
}
return - 1;
}
void deposit(struct customer list[], int s, int number, int amt)
{
int i = search(list, s, number);
if (i == - 1)
{
printf("Record not found");
}
else
{
list[i].balance += amt;
}
}
void withdraw(struct customer list[], int s, int number, int amt)
{
int i = search(list, s, number);
if (i == - 1)
{
printf("Record not found\n");
}
else if (list[i].balance < amt)
{
printf("Insufficient balance\n");
45
}
else
{
list[i].balance -= amt;
}
}
OUTPUT
47
Criteria Score
RESULT
Thus Choose an appropriate data structure and create a token system for banking
service (withdrawal, deposit and money transfer was executed and output was verified
successfully.
48
Ex. No.: 10 FOOD DELIVERING SYSTEM
Date:
AIM
To create a food delivering system which allocates the path for delivery of food using
appropriate data structures
ALGORITHM
PROGRAM
49
void signup();
// Function to check whether account
// is already existed or not
void account_check();
// Function to validate all input fields
int validate();
void login();
void cart();
void search_by_hotels();
void search_by_food();
void food_order(int food);
// Function to initialize the hotels and
// food structure dynamically
void hotel_initialize();
void hotels(int hotel_choice);
int flag = 1, i, j = 0, count = 0, caps = 0;
int small = 0, special = 0, numbers = 0;
int success = 0, x, choice;
char temp_name[100], temp_password1[100];
char temp_password2[100], temp_email[100];
char temp_mobile[100];
int temp_age, total = 0, food_choice, n;
int hotel_choice, search_choice, confirm;
int ch, food, hotel_id;
OUTPUT
50
51
Criteria Score
RESULT
Thus, to Create a food delivering system which allocates the path for delivery
of food using appropriate data structures was executed and output was verified
successfully.
52
Ex. No.: 11 BOOK RACK ALLOCATION SYSTEM
Date:
AIM
To create a book rack allocation system in a library, which allocates appropriate space for
the books based on category using appropriate data structures
ALGORITHM
PROGRAM
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct library{
char bookname[50];
char author[50];
int noofpages;
float price;
};
int main(){
struct library lib[100];
char bookname[30];
int i,j, keepcount;
i=j=keepcount = 0;
while(j!=6){
printf("\n1. Add book information\n");
printf("2.Display book information\n");
printf("3. no of books in the library\n");
printf("4. Exit");
printf ("\n\nEnter one of the above : ");
scanf("%d",&j);
switch (j){
/* Add book */
case 1:
printf ("Enter book name = ");
scanf ("%s",lib[i].bookname);
printf ("Enter author name = ");
scanf ("%s",lib[i].author);
printf ("Enter pages = ");
53
scanf ("%d",&lib[i].noofpages);
printf ("Enter price = ");
scanf ("%f",&lib[i].price);
keepcount++;
i++;
break;
case 2:
printf("you have entered the following information\n");
for(i=0; i<keepcount; i++){
printf ("book name = %s\n",lib[i].bookname);
printf ("\t author name = %s\n",lib[i].author);
printf ("\t pages = %d\n",lib[i].noofpages);
printf ("\t price = %f\n",lib[i].price);
}
break;
case 3:
printf("\n No of books in library : %d", keepcount);
break;
case 4:
exit (0);
}
}
return 0;
}
OUTPUT
Criteria Score
RESULT
55