(04711604421) Arun Kumar

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 86

BHARATI VIDYAPEETH’S

INSTITUTE OF COMPUTER APPLICATIONS & MANAGEMENT

Data and File Structures Lab


(MCA-162)
MCA - II Semester

Submitted to: Submitted by:


Dr. Sunil Pratap Singh Arun Kumar
(Associate Professor) MCA Sem.-2 Sec.-1
(04711604421)

Arun kumar(04711604421)
S.No. Problem Description
AP1 Write a program which takes an array of n integers and
displays the frequency of each element present in the array.

AP2 Write a program which takes an array of n integers and


performs searching of an element by implementing linear
search and binary search techniques.

AP3 Write a program which takes an array of n integers and


sorts the integers in descending order using bubble sort and
selection sort techniques.
AP4 Write a program which takes an array of n integers and
sorts the integers in ascending order using insertion sort
technique.
AP5 Write a program which takes an array of n integers and
sorts the integers in ascending order using quick sort
technique.
BP1 Write a menu-driven program which implements a linear
linked list with following operations:
a) Insertion of an element at beginning of the list
b) Insertion of an element at specific location of the list
c) Insertion of an element at end of the list
d) Deletion of an element from the beginning of the list
e) Deletion of an element from specific location of the list
f) Deletion of an element from the end of the list
g) Display all elements of the list
h) Search a specific element in the list
BP2 A polynomial is composed of different terms where each of
them holds a coefficient and an exponent. Write a program
to represent the following polynomials: 4x4 + 4x3 -2x2 + x
and 11x3 + 7x2 - 4x with linear linked list, and then perform
addition of the given polynomials.
CP1 Write a menu-driven program which implements a stack
(using onedimensional array) with following operations: a)

Arun kumar(04711604421)
Push (insert an element) b) Pop (delete an element) c)
Display (print all the elements of stack)
CP2 Write a menu-driven program which implements a linear
queue (using one-dimensional array) with following
operations: a) Enqueue (insert an element) b) Dequeue
(delete an element) c) Display (print all the elements of
queue)
CP3 Write a menu-driven program which implements a circular
queue (using one-dimensional array) with following
operations: a) Enqueue (insert an element) b) Dequeue
(delete an element) c) Display (print all the elements of
queue)
DP1 Write a menu-driven program which implements a binary tree (using
linked list) with following operations: a) Insertion of a node b)
Deletion of a node c) Preorder traversal d) Inorder traversal e)
Postorder traversal f) Determine total number of leaf nodes
DP2 Write a menu-driven program which implements a heap (using one
dimensional array) with following operations: a) Insertion of a node
b) Deletion of a node c) Display (print all the elements of heap)
DP3 Write a menu-driven program which implements a binary search
tree (using linked list) with following operations: a) Insertion of a
node b) Deletion of a node c) Preorder traversal d) Inorder traversal
e) Postorder traversal
DP4 Write a program which takes an array of n integers and sorts the
integers in ascending order using heap sort technique.

EP1 Write a menu-driven program which implements a graph (using


adjacency matrix) with following operations: g) Insertion of a vertex
h) Insertion of an edge i) Deletion of a vertex j) Deletion of an edge
k) Calculation of degree of each vertex l) Calculation of number of
self-loops in the graph
EP2 Write a program to traverse the following graph using breadth first
search and depth first search techniques.

EP3 Write a program to determine shortest path from a to f (using


Dijkstra‟s algorithm) in the following graph.

Arun kumar(04711604421)
EP4 Write a program to determine shortest paths between every pair of
vertices (using Floyd Warshell‟s algorithm) in the following graph.

FP1 Write a program that generates n random integers and stores them
in a text file, named as “All.txt”. Then, retrieve the stored integers
from this file and copy to “Odd.txt” and „Even.txt‟ based upon the
type of number, i.e. if the retrieved integer is odd number then store
in “Odd.txt” file or if the retrieved integer is even then store in
“Even.txt” file. Finally, display the contents of all three files
FP2 A text file contains the student‟s grade, followed by the student‟s
name. Sample data is following: 8.3 Gautam 9.4 Jasleen 6.7 Gaurav
9.4 Naman 5.7 Ishika 7.5 Rakesh Write a program to find the highest
grade, and list all the students who have highest grade. Also, list the
details of students‟ having 3rd highest grade
FP3 Write a program to implement 20 integers (with some duplicate
integers) in a hash table (with separate chaining for collision
resolution).

AP1:
Soln:
#include <stdio.h>
void findFrequency(int A[], int n)
{
int freq[n];
for (int i = 0; i < n; i++) {
freq[i] = 0;
}

Arun kumar(04711604421)
for (int i = 0; i < n; i++) {
freq[A[i]]++;
}
for (int i = 0; i < n; i++)
{
if (freq[i]) {
printf("%d appears %d times\n", i, freq[i]);
}
}
}
int main(void)
{
int A[] = { 2, 3, 3, 2, 1 };
int n = sizeof(A) / sizeof(A[0]);
printf("Code By Arun Kumar");

findFrequency(A, n);

return 0;
}
Output:

Arun kumar(04711604421)
AP2:
Soln:

#include <stdio.h>
int search(int arr[], int n, int x)
{
int i;
for (i = 0; i < n; i++)
if (arr[i] == x)
return i;
return -1;
}
int main(void)
{
int arr[] = { 2, 3, 4, 10, 40 };
int x = 10;
int n = sizeof(arr) / sizeof(arr[0]);
int result = search(arr, n, x);
printf("Code by Arun \n");

if(result == -1)
printf("Element is not present in array");
printf("Element is present at index %d", result);
return 0;
}

Arun kumar(04711604421)
Output:

AP3:
Soln:
#include <stdio.h>
void swap(int* xp, int* yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
void bubbleSort(int arr[], int n)
{
int i, j;
for (i = 0; i < n - 1; i++)
for (j = 0; j < n - i - 1; j++)
if (arr[j] > arr[j + 1])
swap(&arr[j], &arr[j + 1]);
}
void printArray(int arr[], int size)
{
int i;
for (i = 0; i < size; i++)

Arun kumar(04711604421)
printf("%d ", arr[i]);
printf("\n");
}
int main()
{
int arr[] = { 64, 34, 25, 12, 22, 11, 90 };
int n = sizeof(arr) / sizeof(arr[0]);
printf("Code by Arun \n");
bubbleSort(arr, n);
printf("Sorted array: \n");
printArray(arr, n);
return 0;
}
Ouput:

AP4:
Soln:
#include <math.h>
#include <stdio.h>
void insertionSort(int arr[], int n)
{
int i, key, j;

Arun kumar(04711604421)
for (i = 1; i < n; i++) {
key = arr[i];
j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
void printArray(int arr[], int n)
{
int i;
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
}
int main()
{
int arr[] = { 12, 11, 13, 5, 6 };
int n = sizeof(arr) / sizeof(arr[0]);
printf("code By Arun \n");
insertionSort(arr, n);
printArray(arr, n);

return 0;

Arun kumar(04711604421)
}
Output:

AP5:
Soln:
#include <stdio.h>
void swap(int *a, int *b) {
int t = *a;
*a = *b;
*b = t;
}
int partition(int array[], int low, int high) {
int pivot = array[high];
int i = (low - 1);
for (int j = low; j < high; j++) {
if (array[j] <= pivot) {
i++;
swap(&array[i], &array[j]);
}
}
swap(&array[i + 1], &array[high]);
return (i + 1);
}

Arun kumar(04711604421)
void quickSort(int array[], int low, int high) {
if (low < high) {
int pi = partition(array, low, high);
quickSort(array, low, pi - 1);
quickSort(array, pi + 1, high);
}
}
void printArray(int array[], int size) {
for (int i = 0; i < size; ++i) {
printf("%d ", array[i]);
}
printf("\n");
}
int main() {
int data[] = {8, 7, 2, 1, 0, 9, 6};
int n = sizeof(data) / sizeof(data[0]);
printf("Code By Arun \n");
printf("Unsorted Array\n");

printArray(data, n);
quickSort(data, 0, n - 1);
printf("Sorted array in ascending order: \n");
printArray(data, n);
}
Output:

Arun kumar(04711604421)
BP1:
Soln:
#include <stdio.h>
#include <stdlib.h>
struct node {
int info;
struct node* link;
};
struct node* start = NULL;
void createList()
{
if (start == NULL) {
int n;
printf("\nEnter the number of nodes: ");
scanf("%d", &n);
if (n != 0) {
int data;
struct node* newnode;
struct node* temp;
newnode = malloc(sizeof(struct node));
start = newnode;
temp = start;

Arun kumar(04711604421)
printf("\nEnter number to"
" be inserted : ");
scanf("%d", &data);
start->info = data;

for (int i = 2; i <= n; i++) {


newnode = malloc(sizeof(struct node));
temp->link = newnode;
printf("\nEnter number to"
" be inserted : ");
scanf("%d", &data);
newnode->info = data;
temp = temp->link;
}
}
printf("\nThe list is created\n");
}
else
printf("\nThe list is already created\n");
}
void traverse()
{
struct node* temp;
if (start == NULL)
printf("\nList is empty\n");
else {

Arun kumar(04711604421)
temp = start;
while (temp != NULL) {
printf("Data = %d\n", temp->info);
temp = temp->link;
}
}
}
void insertAtFront()
{
int data;
struct node* temp;
temp = malloc(sizeof(struct node));
printf("\nEnter number to"
" be inserted : ");
scanf("%d", &data);
temp->info = data;
temp->link = start;
start = temp;
}
void insertAtEnd()
{
int data;
struct node *temp, *head;
temp = malloc(sizeof(struct node));
printf("\nEnter number to"
" be inserted : ");

Arun kumar(04711604421)
scanf("%d", &data);
temp->link = 0;
temp->info = data;
head = start;
while (head->link != NULL) {
head = head->link;
}
head->link = temp;
}
void insertAtPosition()
{
struct node *temp, *newnode;
int pos, data, i = 1;
newnode = malloc(sizeof(struct node));
printf("\nEnter position and data :");
scanf("%d %d", &pos, &data);
temp = start;
newnode->info = data;
newnode->link = 0;
while (i < pos - 1) {
temp = temp->link;
i++;
}
newnode->link = temp->link;
temp->link = newnode;
}

Arun kumar(04711604421)
void deleteFirst()
{
struct node* temp;
if (start == NULL)
printf("\nList is empty\n");
else {
temp = start;
start = start->link;
free(temp);
}
}
void deleteEnd()
{
struct node *temp, *prevnode;
if (start == NULL)
printf("\nList is Empty\n");
else {
temp = start;
while (temp->link != 0) {
prevnode = temp;
temp = temp->link;
}
free(temp);
prevnode->link = 0;
}
}

Arun kumar(04711604421)
void deletePosition()
{
struct node *temp, *position;
int i = 1, pos;
if (start == NULL)
printf("\nList is empty\n");

else {
printf("\nEnter index : ");
scanf("%d", &pos);
position = malloc(sizeof(struct node));
temp = start;
while (i < pos - 1) {
temp = temp->link;
i++;
}
position = temp->link;
temp->link = position->link;
free(position);
}
}
void maximum()
{
int a[10];
int i;
struct node* temp;

Arun kumar(04711604421)
if (start == NULL)
printf("\nList is empty\n");
else {
temp = start;
int max = temp->info;
while (temp != NULL) {
if (max < temp->info)
max = temp->info;
temp = temp->link;
}
printf("\nMaximum number "
"is : %d ",
max);
}
}
void mean()
{
int a[10];
int i;
struct node* temp;
if (start == NULL)
printf("\nList is empty\n");
else {
temp = start;
int sum = 0, count = 0;
float m;

Arun kumar(04711604421)
while (temp != NULL) {
sum = sum + temp->info;
temp = temp->link;
count++;
}
m = sum / count;
printf("\nMean is %f ", m);
}
}
void sort()
{
struct node* current = start;
struct node* index = NULL;
int temp;
if (start == NULL) {
return;
}
else {
while (current != NULL) {
index = current->link;
while (index != NULL) {
if (current->info > index->info) {
temp = current->info;
current->info = index->info;
index->info = temp;
}

Arun kumar(04711604421)
index = index->link;
}
current = current->link;
}
}
}
void reverseLL()
{
struct node *t1, *t2, *temp;
t1 = t2 = NULL;
if (start == NULL)
printf("List is empty\n");
else {
while (start != NULL) {
t2 = start->link;
start->link = t1;
t1 = start;
start = t2;
}
start = t1;
temp = start;
printf("Reversed linked "
"list is : ");
while (temp != NULL) {
printf("%d ", temp->info);
temp = temp->link;

Arun kumar(04711604421)
}
}
}
int main()
{
printf("Code By Jeevan \n" );
int choice;
while (1) {

printf("\n\t1 To see list\n");


printf("\t2 For insertion at"
" starting\n");
printf("\t3 For insertion at"
" end\n");
printf("\t4 For insertion at "
"any position\n");
printf("\t5 For deletion of "
"first element\n");
printf("\t6 For deletion of "
"last element\n");
printf("\t7 For deletion of "
"element at any position\n");
printf("\t8 To find maximum among"
" the elements\n");
printf("\t9 To find mean of "
"the elements\n");

Arun kumar(04711604421)
printf("\t10 To sort element\n");
printf("\t11 To reverse the "
"linked list\n");
printf("\t12 To exit\n");
printf("\nEnter Choice :\n");
scanf("%d", &choice);

switch (choice) {
case 1:
traverse();
break;
case 2:
insertAtFront();
break;
case 3:
insertAtEnd();
break;
case 4:
insertAtPosition();
break;
case 5:
deleteFirst();
break;
case 6:
deleteEnd();
break;

Arun kumar(04711604421)
case 7:
deletePosition();
break;
case 8:
maximum();
break;
case 9:
mean();
break;
case 10:
sort();
break;
case 11:
reverseLL();
break;
case 12:
exit(1);
break;
default:
printf("Incorrect Choice\n");
}
}
return 0;
}
Output:

Arun kumar(04711604421)
BP2:
Soln:
#include <bits/stdc++.h>
using namespace std;
struct Node {
int coeff;
int pow;
struct Node* next;
};

void create_node(int x, int y, struct Node** temp)


{
struct Node *r, *z;
z = *temp;
if (z == NULL) {
r = (struct Node*)malloc(sizeof(struct Node));
r->coeff = x;
r->pow = y;
*temp = r;
r->next = (struct Node*)malloc(sizeof(struct Node));

Arun kumar(04711604421)
r = r->next;
r->next = NULL;
}
else {
r->coeff = x;
r->pow = y;
r->next = (struct Node*)malloc(sizeof(struct Node));
r = r->next;
r->next = NULL;
}
}
void polyadd(struct Node* poly1, struct Node* poly2,
struct Node* poly)
{
while (poly1->next && poly2->next) {
if (poly1->pow > poly2->pow) {
poly->pow = poly1->pow;
poly->coeff = poly1->coeff;
poly1 = poly1->next;
}
else if (poly1->pow < poly2->pow) {
poly->pow = poly2->pow;
poly->coeff = poly2->coeff;
poly2 = poly2->next;
}
else {

Arun kumar(04711604421)
poly->pow = poly1->pow;
poly->coeff = poly1->coeff + poly2->coeff;
poly1 = poly1->next;
poly2 = poly2->next;
}
poly->next
= (struct Node*)malloc(sizeof(struct Node));
poly = poly->next;
poly->next = NULL;
}
while (poly1->next || poly2->next) {
if (poly1->next) {
poly->pow = poly1->pow;
poly->coeff = poly1->coeff;
poly1 = poly1->next;
}
if (poly2->next) {
poly->pow = poly2->pow;
poly->coeff = poly2->coeff;
poly2 = poly2->next;
}
poly->next
= (struct Node*)malloc(sizeof(struct Node));
poly = poly->next;
poly->next = NULL;
}

Arun kumar(04711604421)
}
void show(struct Node* node)
{
while (node->next != NULL) {
printf("%dx^%d", node->coeff, node->pow);
node = node->next;
if (node->coeff >= 0) {
if (node->next != NULL)
printf("+");
}
}
}
int main()
{
struct Node *poly1 = NULL, *poly2 = NULL, *poly = NULL;
create_node(5, 2, &poly1);
create_node(4, 1, &poly1);
create_node(2, 0, &poly1);
create_node(-5, 1, &poly2);
create_node(-5, 0, &poly2);

printf("1st Number: ");


show(poly1);

printf("\n2nd Number: ");


show(poly2);

Arun kumar(04711604421)
poly = (struct Node*)malloc(sizeof(struct Node));

polyadd(poly1, poly2, poly);

printf("\nAdded polynomial: ");


show(poly);

return 0;
}

OUTPUT:-

CP1:
Soln:
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
struct Stack {
int top;
unsigned capacity;
int* array;
};
struct Stack* createStack(unsigned capacity)
{

Arun kumar(04711604421)
struct Stack* stack = (struct Stack*)malloc(sizeof(struct Stack));
stack->capacity = capacity;
stack->top = -1;
stack->array = (int*)malloc(stack->capacity * sizeof(int));
return stack;
}
int isFull(struct Stack* stack)
{
return stack->top == stack->capacity - 1;
}
int isEmpty(struct Stack* stack)
{
return stack->top == -1;
}
void push(struct Stack* stack, int item)
{
if (isFull(stack))
return;
stack->array[++stack->top] = item;
printf("%d pushed to stack\n", item);
}
int pop(struct Stack* stack)
{
if (isEmpty(stack))
return INT_MIN;
return stack->array[stack->top--];

Arun kumar(04711604421)
}
int peek(struct Stack* stack)
{
if (isEmpty(stack))
return INT_MIN;
return stack->array[stack->top];
}
int main()
{
struct Stack* stack = createStack(100);
push(stack, 10);
push(stack, 20);
push(stack, 30);
printf("%d popped from stack\n", pop(stack));
return 0;
}
Output:

CP2:
Soln:
#include <limits.h>
#include <stdio.h>

Arun kumar(04711604421)
#include <stdlib.h>
struct Queue {
int front, rear, size;
unsigned capacity;
int* array;
};
struct Queue* createQueue(unsigned capacity)
{
struct Queue* queue = (struct Queue*)malloc(
sizeof(struct Queue));
queue->capacity = capacity;
queue->front = queue->size = 0;
queue->rear = capacity - 1;
queue->array = (int*)malloc(
queue->capacity * sizeof(int));
return queue;
}
int isFull(struct Queue* queue)
{
return (queue->size == queue->capacity);
}

int isEmpty(struct Queue* queue)


{
return (queue->size == 0);
}

Arun kumar(04711604421)
void enqueue(struct Queue* queue, int item)
{
if (isFull(queue))
return;
queue->rear = (queue->rear + 1)
% queue->capacity;
queue->array[queue->rear] = item;
queue->size = queue->size + 1;
printf("%d enqueued to queue\n", item);
}
int dequeue(struct Queue* queue)
{
if (isEmpty(queue))
return INT_MIN;
int item = queue->array[queue->front];
queue->front = (queue->front + 1)
% queue->capacity;
queue->size = queue->size - 1;
return item;
}
int front(struct Queue* queue)
{
if (isEmpty(queue))
return INT_MIN;
return queue->array[queue->front];
}

Arun kumar(04711604421)
int rear(struct Queue* queue)
{
if (isEmpty(queue))
return INT_MIN;
return queue->array[queue->rear];
}
int main()
{
struct Queue* queue = createQueue(1000);
enqueue(queue, 10);
enqueue(queue, 20);
enqueue(queue, 30);
enqueue(queue, 40);
printf("%d dequeued from queue\n\n",
dequeue(queue));
printf("Front item is %d\n", front(queue));
printf("Rear item is %d\n", rear(queue));
return 0;
}
Output:

Arun kumar(04711604421)
CP3:
Soln:
#include <stdio.h>
#define SIZE 5
int items[SIZE];
int front = -1, rear = -1;
int isFull() {
if ((front == rear + 1) || (front == 0 && rear == SIZE - 1)) return 1;
return 0;
}
int isEmpty() {
if (front == -1) return 1;
return 0;
}
void enQueue(int element) {
if (isFull())
printf("\n Queue is full!! \n");
else {

Arun kumar(04711604421)
if (front == -1) front = 0;
rear = (rear + 1) % SIZE;
items[rear] = element;
printf("\n Inserted -> %d", element);
}
}
int deQueue() {
int element;
if (isEmpty()) {
printf("\n Queue is empty !! \n");
return (-1);
} else {
element = items[front];
if (front == rear) {
front = -1;
rear = -1;
}
else {
front = (front + 1) % SIZE;
}
printf("\n Deleted element -> %d \n", element);
return (element);
}
}
void display() {
int i;

Arun kumar(04711604421)
if (isEmpty())
printf(" \n Empty Queue\n");
else {
printf("\n Front -> %d ", front);
printf("\n Items -> ");
for (i = front; i != rear; i = (i + 1) % SIZE) {
printf("%d ", items[i]);
}
printf("%d ", items[i]);
printf("\n Rear -> %d \n", rear);
}
}

int main() {
deQueue();
enQueue(1);
enQueue(2);
enQueue(3);
enQueue(4);
enQueue(5);
enQueue(6);

display();
deQueue();
display();
enQueue(7);

Arun kumar(04711604421)
display();
enQueue(8);
return 0;
}
Output:

DP1:-
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
struct node{
int data;
struct node *left;
struct node *right;
};

Arun kumar(04711604421)
struct node *root = NULL;
struct node* createNode(int data){
struct node *newNode = (struct node*)malloc(sizeof(struct node));
newNode->data = data;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
}
struct queue
{
int front, rear, size;
struct node* *arr;
};
struct queue* createQueue()
{
struct queue* newQueue = (struct queue*) malloc(sizeof( struct queue ));
newQueue->front = -1;
newQueue->rear = 0;
newQueue->size = 0;
newQueue->arr = (struct node**) malloc(100 * sizeof( struct node* ));
return newQueue;
}
void enqueue(struct queue* queue, struct node *temp){
queue->arr[queue->rear++] = temp;
queue->size++;
}

Arun kumar(04711604421)
struct node *dequeue(struct queue* queue){
queue->size--;
return queue->arr[++queue->front];
}
void insertNode(int data) {
struct node *newNode = createNode(data);
if(root == NULL){
root = newNode;
return;
}
else {
struct queue* queue = createQueue();
enqueue(queue, root);
while(true) {
struct node *node = dequeue(queue);
if(node->left != NULL && node->right != NULL) {
enqueue(queue, node->left);
enqueue(queue, node->right);
}
else {
if(node->left == NULL) {
node->left = newNode;
enqueue(queue, node->left);
}
else {
node->right = newNode;

Arun kumar(04711604421)
enqueue(queue, node->right);
}
break;
}
}
}
}
void inorderTraversal(struct node *node) {
if(root == NULL){
printf("Tree is empty\n");
return;
}
else {
if(node->left != NULL)
inorderTraversal(node->left);
printf("%d ", node->data);
if(node->right != NULL)
inorderTraversal(node->right);
}
}
void preorderTraversal(struct node *node) {
if(root == NULL){
printf("Tree is empty\n");
return;
}
else {

Arun kumar(04711604421)
printf("%d ", node->data);
if(node->left != NULL)
inorderTraversal(node->left);
if(node->right != NULL)
inorderTraversal(node->right);
}
}
void postorderTraversal(struct node *node) {
if(root == NULL){
printf("Tree is empty\n");
return;
}
else {
if(node->left != NULL)
inorderTraversal(node->left);
if(node->right != NULL)
inorderTraversal(node->right);
printf("%d ", node->data);
}
}
int main(){
while (1) {
printf("\t1 For insertion \n");
printf("\t2 For deletion \n");
printf("\t3 For traversse -inorder\n");
printf("\t4 For traversse -preorder\n");

Arun kumar(04711604421)
printf("\t5 For traversse -postorder\n");
printf("\nEnter Choice :\n");
scanf("%d", &choice);
switch (choice) {
case 1:
insertNode(1);
insertNode(2);
insertNode(3);
insertNode(4);
insertNode(5);
insertNode(6);
insertNode(7);
break;
case 2:
break;
case 3:
printf("\nBinary tree inorder traversal: \n");
inorderTraversal(root);
break;
case 4:
printf("\nBinary tree preorder traversal: \n");
preorderTraversal(root);
break;
case 5:
printf("\nBinary tree postorder traversal: \n");
postorderTraversal(root);

Arun kumar(04711604421)
break;
default:
printf("Incorrect Choice\n");
}
}
printf("\n Arun Kumar\n");
return 0;
}
OUTPUT:-

DP2:-
#include <stdio.h>
int size = 0;
void swap(int *a, int *b)
{
int temp = *b;
*b = *a;
*a = temp;
}

Arun kumar(04711604421)
void heapify(int array[], int size, int i)
{
if (size == 1)
{
printf("Single element in the heap");
}
else
{
int largest = i;
int l = 2 * i + 1;
int r = 2 * i + 2;
if (l < size && array[l] > array[largest])
largest = l;
if (r < size && array[r] > array[largest])
largest = r;
if (largest != i)
{
swap(&array[i], &array[largest]);
heapify(array, size, largest);
}
}
}
void insert(int array[], int newNum)
{
if (size == 0)
{

Arun kumar(04711604421)
array[0] = newNum;
size += 1;
}
else
{
array[size] = newNum;
size += 1;
for (int i = size / 2 - 1; i >= 0; i--)
{
heapify(array, size, i);
}
}
}
void deleteRoot(int array[], int num)
{
int i;
for (i = 0; i < size; i++)
{
if (num == array[i])
break;
}
swap(&array[i], &array[size - 1]);
size -= 1;
for (int i = size / 2 - 1; i >= 0; i--)
{
heapify(array, size, i);

Arun kumar(04711604421)
}
}
void printArray(int array[], int size)
{
for (int i = 0; i < size; ++i)
printf("%d ", array[i]);
printf("\n");
}
int main()
{
int array[10];
insert(array, 3);
insert(array, 4);
insert(array, 9);
insert(array, 5);
insert(array, 2);
printf("Max-Heap array: ");
printArray(array, size);
deleteRoot(array, 4);
printf("After deleting an element: ");
printArray(array, size);
printf("\n Arun Kumar\n");

OUTPUT:-

Arun kumar(04711604421)
DP3:-
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
struct node{
int data;
struct node *left;
struct node *right;
};
struct node *root = NULL;
struct node* createNode(int data){
struct node *newNode = (struct node*)malloc(sizeof(struct node));
newNode->data = data;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
}
struct queue
{
int front, rear, size;
struct node* *arr;

Arun kumar(04711604421)
};
struct queue* createQueue()
{
struct queue* newQueue = (struct queue*) malloc(sizeof( struct queue ));
newQueue->front = -1;
newQueue->rear = 0;
newQueue->size = 0;
newQueue->arr = (struct node**) malloc(100 * sizeof( struct node* ));
return newQueue;
}
void enqueue(struct queue* queue, struct node *temp){
queue->arr[queue->rear++] = temp;
queue->size++;
}
struct node *dequeue(struct queue* queue){
queue->size--;
return queue->arr[++queue->front];
}
void insertNode(int data) {
struct node *newNode = createNode(data);
if(root == NULL){
root = newNode;
return;
}
else {
struct queue* queue = createQueue();

Arun kumar(04711604421)
enqueue(queue, root);
while(true) {
struct node *node = dequeue(queue);
if(node->left != NULL && node->right != NULL) {
enqueue(queue, node->left);
enqueue(queue, node->right);
}
else {
if(node->left == NULL) {
node->left = newNode;
enqueue(queue, node->left);
}
else {
node->right = newNode;
enqueue(queue, node->right);
}
break;
}
}
}
}
void inorderTraversal(struct node *node) {
if(root == NULL){
printf("Tree is empty\n");
return;
}

Arun kumar(04711604421)
else {
if(node->left != NULL)
inorderTraversal(node->left);
printf("%d ", node->data);
if(node->right != NULL)
inorderTraversal(node->right);
}
}
void preorderTraversal(struct node *node) {
if(root == NULL){
printf("Tree is empty\n");
return;
}
else {
printf("%d ", node->data);
if(node->left != NULL)
inorderTraversal(node->left);
if(node->right != NULL)
inorderTraversal(node->right);
}
}
void postorderTraversal(struct node *node) {
if(root == NULL){
printf("Tree is empty\n");
return;
}

Arun kumar(04711604421)
else {
if(node->left != NULL)
inorderTraversal(node->left);
if(node->right != NULL)
inorderTraversal(node->right);
printf("%d ", node->data);
}
}
int main(){
int choice;
printf("\n Arun Kumar \n");
while (1) {
printf("\t1 For insertion \n");
printf("\t2 For deletion \n");
printf("\t3 For traversse -inorder\n");
printf("\t4 For traversse -preorder\n");
printf("\t5 For traversse -postorder\n");
printf("\nEnter Choice :\n");
scanf("%d", &choice);
switch (choice) {
case 1:
insertNode(1);
insertNode(2);
insertNode(3);
insertNode(4);
insertNode(5);

Arun kumar(04711604421)
insertNode(6);
insertNode(7);
break;
case 2:
break;
case 3:
printf("\nBinary tree inorder traversal: \n");
inorderTraversal(root);
break;
case 4:
printf("\nBinary tree preorder traversal: \n");
preorderTraversal(root);
break;
case 5:
printf("\nBinary tree postorder traversal: \n");
postorderTraversal(root);
break;
default:
printf("Incorrect Choice\n");
}
}
return 0;
}

OUTPUT:-

Arun kumar(04711604421)
DP4:-
#include <stdio.h>
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
void heapify(int arr[], int n, int i) {
int largest = i;
int left = 2 * i + 1;
int right = 2 * i + 2;
if (left < n && arr[left] > arr[largest])
largest = left;
if (right < n && arr[right] > arr[largest])
largest = right;
if (largest != i) {
swap(&arr[i], &arr[largest]);
heapify(arr, n, largest);
}
}
void heapSort(int arr[], int n) {

Arun kumar(04711604421)
for (int i = n / 2 - 1; i >= 0; i--)
heapify(arr, n, i);
for (int i = n - 1; i >= 0; i--) {
swap(&arr[0], &arr[i]);
heapify(arr, i, 0);
}
}
void printArray(int arr[], int n)
{
for (int i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
}
int main()
{
int n;
int arr[n];
printf("\nEnter Size of array :\n");
scanf("%d", &n);
printf("\n enter element of array \n");
for(int i = 0; i < n; ++i) {
scanf("%d", &arr[i]);
}
heapSort(arr, n);
printf("Sorted array is given in the following way \n");
printArray(arr, n);

Arun kumar(04711604421)
printf("\n JEEVAN PATIDAR\n");
return 0;
}
OUTPUT:-

EP1:-
#include<stdio.h>
#include<stdlib.h>
struct Edge;
struct Vertex
{
int info;
struct Vertex *nextVertex;
struct Edge *firstEdge;
}*start = NULL;
struct Edge
{
struct Vertex *destVertex;
struct Edge *nextEdge;
};
struct Vertex *findVertex(int u);

Arun kumar(04711604421)
void insertVertex(int u);
void insertEdge(int u,int v);
void deleteEdge(int u,int v);
void deleteIncomingEdges(int u);
void deleteVertex(int u);
void display();
void insertVertex(int u)
{
struct Vertex *ptr;
struct Vertex *tmp = (struct Vertex *)malloc(sizeof(struct Vertex));
tmp->info = u;
tmp->nextVertex = NULL;
tmp->firstEdge = NULL;
if(start == NULL)
{
start = tmp;
return;
}
ptr = start;
while(ptr->nextVertex!=NULL)
ptr = ptr->nextVertex;
ptr->nextVertex = tmp;
}
void deleteVertex(int u)
{
struct Vertex *tmp,*q;

Arun kumar(04711604421)
struct Edge *p,*temporary;
if(start == NULL)
{
printf("\nNo vertices to be deleted\n");
return;
}
if(start->info == u)
{
tmp = start;
start = start->nextVertex;
}
else
{
q = start;
while(q->nextVertex != NULL)
{
if(q->nextVertex->info == u)
break;
q = q->nextVertex;
}
if(q->nextVertex==NULL)
{
printf("Vertex not found\n");
return;
}
else

Arun kumar(04711604421)
{
tmp = q->nextVertex;
q->nextVertex = tmp->nextVertex;
}
}
p = tmp->firstEdge;
while(p!=NULL)
{
temporary = p;
p = p->nextEdge;
free(temporary);
}
free(tmp);
}
void deleteIncomingEdges(int u)
{
struct Vertex *ptr;
struct Edge *q,*tmp;
ptr = start;
while(ptr!=NULL)
{
if(ptr->firstEdge == NULL)
{
ptr = ptr->nextVertex;
continue;
}

Arun kumar(04711604421)
if(ptr->firstEdge->destVertex->info == u)
{
tmp = ptr->firstEdge;
ptr->firstEdge = ptr->firstEdge->nextEdge;
free(tmp);
continue;
}
q = ptr->firstEdge;
while(q->nextEdge!= NULL)
{ if(q->nextEdge->destVertex->info == u)
{
tmp = q->nextEdge;
q->nextEdge = tmp->nextEdge;
free(tmp);
continue;
}
q = q->nextEdge;
}
ptr = ptr->nextVertex;
}
}
struct Vertex *findVertex(int u)
{
struct Vertex *ptr,*loc;
ptr = start;
while(ptr!=NULL)

Arun kumar(04711604421)
{
if(ptr->info == u )
{
loc = ptr;
return loc;
}
else
ptr = ptr->nextVertex;
}
loc = NULL;
return loc;
}
void insertEdge(int u,int v)
{
struct Vertex *locu,*locv;
struct Edge *ptr,*tmp;
locu = findVertex(u);
locv = findVertex(v);
if(locu == NULL )
{
printf("\nStart vertex not present, first insert vertex %d\n",u);
return;
}
if(locv == NULL )
{
printf("\nEnd vertex not present, first insert vertex %d\n",v);

Arun kumar(04711604421)
return;
}
tmp =(struct Edge *) malloc(sizeof(struct Edge));
tmp->destVertex = locv;
tmp->nextEdge = NULL;
if(locu->firstEdge == NULL)
{
locu->firstEdge = tmp;
return;
}
ptr = locu->firstEdge;
while(ptr->nextEdge!=NULL)
ptr = ptr->nextEdge;
ptr->nextEdge = tmp;
}
void deleteEdge(int u,int v)
{
struct Vertex *locu;
struct Edge *tmp,*q;
locu = findVertex(u);
if(locu == NULL )
{
printf("\nStart vertex not present\n");
return;
}
if(locu->firstEdge == NULL)

Arun kumar(04711604421)
{
printf("\nEdge not present\n");
return;
}
if(locu->firstEdge->destVertex->info == v)
{
tmp = locu->firstEdge;
locu->firstEdge = locu->firstEdge->nextEdge;
free(tmp);
return;
}
q = locu->firstEdge;
while(q->nextEdge != NULL)
{
if(q->nextEdge->destVertex->info == v)
{
tmp = q->nextEdge;
q->nextEdge = tmp->nextEdge;
free(tmp);
return;
}
q = q->nextEdge;
}
printf("\nThis Edge not present in the graph\n");
}
void display()

Arun kumar(04711604421)
{
struct Vertex *ptr;
struct Edge *q;
ptr = start;
while(ptr!=NULL)
{
printf("%d ->",ptr->info);
q = ptr->firstEdge;
while(q!=NULL)
{
printf(" %d",q->destVertex->info);
q = q->nextEdge;
}
printf("\n");
ptr = ptr->nextVertex;
}
}
int main()
{
int choice,u,origin,destin;
printf("\n Arun Kumar\n");
while(1)
{
printf("\n1.Insert a Vertex\n");
printf("2.Insert an Edge\n");
printf("3.Delete a Vertex\n");

Arun kumar(04711604421)
printf("4.Delete an Edge\n");
printf("5.Display\n");
printf("6.Exit\n");
printf("\nEnter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter a vertex to be inserted : ");
scanf("%d",&u);
insertVertex(u);
break;
case 2:
printf("\nEnter an Edge to be inserted : ");
scanf("%d %d",&origin,&destin);
insertEdge(origin,destin);
break;
case 3:
printf("\nEnter a vertex to be deleted : ");
scanf("%d",&u);
deleteIncomingEdges(u);
deleteVertex(u);
break;
case 4:
printf("\nEnter an edge to be deleted : ");
scanf("%d %d",&origin,&destin);

Arun kumar(04711604421)
deleteEdge(origin,destin);
break;
case 5:
display();
break;
case 6:
exit(1);
default:
printf("\nWrong choice\n");
break;
}
}
return 0;
}

OUTPUT:-

EP2:-
#include <stdio.h>

Arun kumar(04711604421)
#include <stdlib.h>
#define SIZE 40
struct node {
int vertex;
struct node* next;
};
struct node* createNode(int v);
struct queue {
int items[SIZE];
int front;
int rear;
};
struct queue* createQueue();
void enqueue(struct queue* q, int);
int dequeue(struct queue* q);
void display(struct queue* q);
int isEmpty(struct queue* q);
void printQueue(struct queue* q);
struct queue* createQueue() {
struct queue* q = (struct queue *)malloc(sizeof(struct queue));
q->front = -1;
q->rear = -1;
return q;
}
int isEmpty(struct queue* q) {
if (q->rear == -1)

Arun kumar(04711604421)
return 1;
else
return 0;
}
void enqueue(struct queue* q, int value) {
if (q->rear == SIZE - 1)
printf("\nQueue is Full!!");
else {
if (q->front == -1)
q->front = 0;
q->rear++;
q->items[q->rear] = value;
}
}
int dequeue(struct queue* q) {
int item;
if (isEmpty(q)) {
printf("Queue is empty");
item = -1;
} else {
item = q->items[q->front];
q->front++;
if (q->front > q->rear) {
printf("Resetting queue ");
q->front = q->rear = -1;
}

Arun kumar(04711604421)
}
return item;
}
void printQueue(struct queue* q) {
int i = q->front;
if (isEmpty(q)) {
printf("Queue is empty");
} else {
printf("\nQueue contains \n");
for (i = q->front; i < q->rear + 1; i++) {
printf("%d ", q->items[i]);
}
}
}
struct node* createNode(int);
struct Graph {
int numVertices;
struct node** adjLists;
int* visited;
};
struct node* createNode(int v) {
struct node* newNode = (struct node *)malloc(sizeof(struct node));
newNode->vertex = v;
newNode->next = NULL;
return newNode;
}

Arun kumar(04711604421)
struct Graph* createGraph(int vertices) {
struct Graph* graph =(struct Graph *) malloc(sizeof(struct Graph));
graph->numVertices = vertices;
graph->adjLists = (struct node **)malloc(vertices * sizeof(struct node*));
graph->visited = (int *)malloc(vertices * sizeof(int));
int i;
for (i = 0; i < vertices; i++) {
graph->adjLists[i] = NULL;
graph->visited[i] = 0;
}
return graph;
}
void addEdge(struct Graph* graph, int src, int dest) {
struct node* newNode = createNode(dest);
newNode->next = graph->adjLists[src];
graph->adjLists[src] = newNode;
newNode = createNode(src);
newNode->next = graph->adjLists[dest];
graph->adjLists[dest] = newNode;
}
void printGraph(struct Graph* graph) {
int v;
for (v = 0; v < graph->numVertices; v++) {
struct node* temp = graph->adjLists[v];
printf("\n Adjacency list of vertex %d\n ", v);
while (temp) {

Arun kumar(04711604421)
printf("%d -> ", temp->vertex);
temp = temp->next;
}
printf("\n");
}
}
void DFS(struct Graph* graph, int vertex) {
struct node* adjList = graph->adjLists[vertex];
struct node* temp = adjList;
graph->visited[vertex] = 1;
printf("%d ", &vertex);
while (temp != NULL) {
int connectedVertex = temp->vertex;
if (graph->visited[connectedVertex] == 0) {
DFS(graph, connectedVertex);
}
temp = temp->next;
}
}
void bfs(struct Graph* graph, int startVertex) {
struct queue* q = createQueue();
graph->visited[startVertex] = 1;
enqueue(q, startVertex);
while (!isEmpty(q)) {
printQueue(q);
int currentVertex = dequeue(q);

Arun kumar(04711604421)
printf("%d ", &currentVertex);
struct node* temp = graph->adjLists[currentVertex];
while (temp) {
int adjVertex = temp->vertex;
if (graph->visited[adjVertex] == 0) {
graph->visited[adjVertex] = 1;
enqueue(q, adjVertex);
}
temp = temp->next;
}
}
}
int main() {
struct Graph* graph = createGraph(4);
addEdge(graph, 0, 1);
addEdge(graph, 0, 2);
addEdge(graph, 1, 2);
addEdge(graph, 2, 3);
printf("\n Arun Kumar\n");
printf("\n graph:- \n");
printGraph(graph);
printf("\n DFS Traversal \n");
DFS(graph, 2);
printf("\n BFS Traversal \n");
bfs(graph,2);
return 0;
}

Arun kumar(04711604421)
OUTPUT:-

EP3 Write a program to determine shortest path from a to f (using Dijkstra‟s


algorithm) in the following graph.
#include<stdio.h>
#include<conio.h>
#define INFINITY 9999
#define MAX 10
void dijkstra(int G[MAX][MAX],int n,int startnode)
{
int cost[MAX][MAX],distance[MAX],pred[MAX];
int visited[MAX],count,mindistance,nextnode,i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(G[i][j]==0)
cost[i][j]=INFINITY;
else

Arun kumar(04711604421)
cost[i][j]=G[i][j];
for(i=0;i<n;i++)
{
distance[i]=cost[startnode][i];
pred[i]=startnode;
visited[i]=0;
}
distance[startnode]=0;
visited[startnode]=1;
count=1;
while(count<n-1)
{
mindistance=INFINITY;
for(i=0;i<n;i++)
if(distance[i]<mindistance&&!visited[i])
{
mindistance=distance[i];
nextnode=i;
}
visited[nextnode]=1;
for(i=0;i<n;i++)
if(!visited[i])
if(mindistance+cost[nextnode][i]<distance[i])
{
distance[i]=mindistance+cost[nextnode][i];
pred[i]=nextnode;

Arun kumar(04711604421)
}
count++;
}
for(i=0;i<n;i++)
if(i!=startnode)
{
printf("\nDistance of node%d=%d",i,distance[i]);
printf("\nPath=%d",i);
j=i;
do
{
j=pred[j];
printf("<-%d",j);
}while(j!=startnode);
}
}
int main()
{
int G[MAX][MAX],i,j,n,u;
printf("\n Arun Kumar\n");
printf("Enter no. of vertices:");
scanf("%d",&n);
printf("\nEnter the adjacency matrix:\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&G[i][j]);

Arun kumar(04711604421)
printf("\nEnter the starting node:");
scanf("%d",&u);
dijkstra(G,n,u);
return 0;
}

OUTPUT:-

EP4 Write a program to determine shortest paths between every pair of


vertices (using Floyd Warshell‟s algorithm) in the following graph.
#include <stdio.h>
#define nV 6
#define INF 999
void printMatrix(int matrix[][nV]);
void floydWarshall(int graph[][nV]) {
int matrix[nV][nV], i, j, k;
for (i = 0; i < nV; i++)
for (j = 0; j < nV; j++)
matrix[i][j] = graph[i][j];
for (k = 0; k < nV; k++) {

Arun kumar(04711604421)
for (i = 0; i < nV; i++) {
for (j = 0; j < nV; j++) {
if (matrix[i][k] + matrix[k][j] < matrix[i][j])
matrix[i][j] = matrix[i][k] + matrix[k][j];
}
}
}
printMatrix(matrix);
}
void printMatrix(int matrix[][nV]) {
for (int i = 0; i < nV; i++) {
for (int j = 0; j < nV; j++) {
if (matrix[i][j] == INF)
printf("%4s", "INF");
else
printf("%4d", matrix[i][j]);
}
printf("\n");
}
}
int main() {
printf("\n Arun \n");
int graph[nV][nV] = {{INF, 3, 9, INF,INF,INF},
{3,INF,8,11,9,INF},
{9, 8,INF,1,INF,2},
{INF,9,1, INF,6,9},

Arun kumar(04711604421)
{INF, 11,INF,6,INF,7},
{INF, INF, 2, 9,7,INF}};
printf("\n floyd warshall algorithm \n");
floydWarshall(graph);
}

OUTPUT:

FP1 Write a program that generates n random integers and stores them in
a text file, named as “All.txt”. Then, retrieve the stored integers from this file
and copy to “Odd.txt” and „Even.txt‟ based upon the type of number, i.e. if
the retrieved integer is odd number then store in “Odd.txt” file or if the
retrieved integer is even then store in “Even.txt” file. Finally, display the
contents of all three files.
#include <stdio.h>
#include <conio.h>
int main()
{
FILE *f1, *f2, *f3;
int number, i;
printf("input the contents of DATA File\n");
f1 = fopen("DATA", "w");

Arun kumar(04711604421)
for (i = 1; i <= 9; i++)
{
scanf("%d", &number);
putw(number, f1);
}
fclose(f1);
f1 = fopen("DATA", "r");
f2 = fopen("ODD", "w");
f3 = fopen("EVEN", "w");
while ((number = getw(f1)) != EOF)
{
if (number % 2 == 0)
{
putw(number, f3);
}
else
{
putw(number, f2);
}
}
fclose(f1);
fclose(f2);
fclose(f3);
f2 = fopen("ODD", "r");
f3 = fopen("EVEN", "r");
printf("\n\nContents of ODD File\n\n");

Arun kumar(04711604421)
while ((number = getw(f2)) != EOF)
printf("%4d", number);
printf("\n\nContents of EVEN File\n\n");
while ((number = getw(f3)) != EOF)
printf("%4d", number);
fclose(f2);
fclose(f3);
printf("\n Arun Kumar\n");
return 0;
}
OUTPUT:-

FP2 A text file contains student‟s grade, followed by student‟s name.


Sample data is following: 8.3 Gautam 9.4 Jasleen 6.7 Gaurav 9.4 Naman
5.7 Ishika 7.5 Rakesh Write a program to find the highest grade, and list all
the students who have highest grade. Also, list the details of students‟
having 3rd highest grade.
#include <stdio.h>
#include <conio.h>
int main()

Arun kumar(04711604421)
{
FILE *fp;
long n;
char c;
fp = fopen("RANDOM", "w");
while ((c = getchar()) != EOF)
{
putc(c, fp);
}
printf("No. of Characters Entered = %1d\n", ftell(fp));
fclose(fp);
fp = fopen("RANDOM", "r");
n = 0;
while (feof(fp) == 0)
{
fseek(fp, -1, 2);
printf("position of %c is %1d\n", getc(fp), ftell(fp));
n = n - 1;
}
return 0;
}

FP3 Write a program to implement 20 integers (with some duplicate


integers) in a hash table (with separate chaining for collision resolution).
#include <stdio.h>
#include <stdlib.h>
struct set

Arun kumar(04711604421)
{
int key;
int data;
};
struct set *array;
int capacity = 10;
int size = 0;
int hashFunction(int key)
{
return (key % capacity);
}
int checkPrime(int n)
{
int i;
if (n == 1 || n == 0)
{
return 0;
}
for (i = 2; i < n / 2; i++)
{
if (n % i == 0)
{
return 0;
}
}
return 1;

Arun kumar(04711604421)
}
int getPrime(int n)
{
if (n % 2 == 0)
{
n++;
}
while (!checkPrime(n))
{
n += 2;
}
return n;
}
void init_array()
{
capacity = getPrime(capacity);
array = (struct set *)malloc(capacity * sizeof(struct set));
for (int i = 0; i < capacity; i++)
{
array[i].key = 0;
array[i].data = 0;
}
}
void insert(int key, int data)
{
int index = hashFunction(key);

Arun kumar(04711604421)
if (array[index].data == 0)
{
array[index].key = key;
array[index].data = data;
size++;
printf("\n Key (%d) has been inserted \n", key);
}
else if (array[index].key == key)
{
array[index].data = data;
}
else
{
printf("\n Collision occured \n");
}
}
void remove_element(int key)
{
int index = hashFunction(key);
if (array[index].data == 0)
{
printf("\n This key does not exist \n");
}
else
{
array[index].key = 0;

Arun kumar(04711604421)
array[index].data = 0;
size--;
printf("\n Key (%d) has been removed \n", key);
}
}
void display()
{
int i;
for (i = 0; i < capacity; i++)
{
if (array[i].data == 0)
{
printf("\n array[%d]: / ", i);
}
else
{
printf("\n key: %d array[%d]: %d \t", array[i].key, i, array[i].data);
}
}
}
int size_of_hashtable()
{
return size;
}
int main()
{

Arun kumar(04711604421)
int choice, key, data, n;
int c = 0;
init_array();
do
{
printf("1.Insert item in the Hash Table"
"\n2.Remove item from the Hash Table"
"\n3.Check the size of Hash Table"
"\n4.Display a Hash Table"
"\n\n Please enter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("Enter key -:\t");
scanf("%d", &key);
printf("Enter data -:\t");
scanf("%d", &data);
insert(key, data);
break;
case 2:
printf("Enter the key to delete-:");
scanf("%d", &key);
remove_element(key);
break;
case 3:

Arun kumar(04711604421)
n = size_of_hashtable();
printf("Size of Hash Table is-:%d\n", n);
break;
case 4:
display();
break;
default:
printf("Invalid Input\n");
}
printf("\nDo you want to continue (press 1 for yes): ");
scanf("%d", &c);
} while (c == 1);
}

Arun kumar(04711604421)

You might also like