0% found this document useful (0 votes)
5 views37 pages

ALL PROGRAMS (1)

The document outlines a series of laboratory components for a Data Structure and Applications course, detailing various programming tasks in C. It includes implementations for array operations, stack operations, singly linked lists, and doubly linked lists, with specific functions for creating, displaying, inserting, deleting, and searching data. Each module provides code examples and describes the expected outputs for the respective operations.

Uploaded by

manisha.rk04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views37 pages

ALL PROGRAMS (1)

The document outlines a series of laboratory components for a Data Structure and Applications course, detailing various programming tasks in C. It includes implementations for array operations, stack operations, singly linked lists, and doubly linked lists, with specific functions for creating, displaying, inserting, deleting, and searching data. Each module provides code examples and describes the expected outputs for the respective operations.

Uploaded by

manisha.rk04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Data Structure and Applications (21CS32) 2022-2023

Module-1
Laboratory Component:

1. Design, Develop and Implement a menu driven Program in C for the


following Array Operations
a. Creating an Array of N Integer Elements
b. Display of Array Elements with Suitable Headings
c. Exit.
Support the program with functions for each of the above operations.

CODE:

#include<stdio.h>
#include<stdlib.h>
int n, i, a[20], opt;
void create()
{
printf("Enter the size of the array elements");
scanf("%d",&n);
printf("Enter the array elements");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}}
void display()
{
printf("The array elements are\n");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}}

main()
{
printf("Program: Array operations 1\n Name: Manisha.K\n USN: 4SN21IS014");
do
{
printf("\n Menu \n");
printf("\n 1.create\n 2.display\n 3.exit\n");
printf("Enter your option\n");
scanf("%d",&opt);
switch(opt)
{
case 1: create();
break;
case 2: display();
break;
case 3: exit(0);
}}
while(1);
}

Dept. of ISE, SIT, Valachil Page 1


Data Structure and Applications (21CS32) 2022-2023

OUTPUT:

Figure 1

Dept. of ISE, SIT, Valachil Page 2


Data Structure and Applications (21CS32) 2022-2023

Laboratory Component:

2. Design, Develop and Implement a menu driven Program in C for the


following Array operations
a. Inserting an Element (ELEM) at a given valid Position (POS)
b. Deleting an Element at a given valid Position POS)
c. Display of Array Elements
d. Exit.

Support the program with functions for each of the above operations.

CODE:

#include <stdio.h >


#include <stdlib.h>
#define MAX 10
int n, i, a[20], opt, pos, elem;
void create() {
printf ("Enter the size of the array elements");
scanf ("%d", &n);
printf ("Enter the array elements");
for (i=0; i<n; i++) {
scanf ("%d", &a[i]);
}
}

void display() {
printf ("The array elements are\n");
for (i=0; i<n; i++) {
printf ("%d\t", a[i]);
}
}

void insert() {
printf ("\n enter the position for new element:");
scanf ("%d",&pos);
printf ("\n enter the element to be inserted:");
scanf ("%d",&elem);
if (n<MAX && pos<=n)
{
for (i=n; i>=pos; i--)
{
a[i+1]=a[i];
}
a[pos]=elem;
n++;
}
}

Dept. of ISE, SIT, Valachil Page 3


Data Structure and Applications (21CS32) 2022-2023

void delete()
{
if (n==0)
{
printf ("\n no elements to delete!!");
}
else
{
printf ("\n enter the position of the element:");
scanf ("%d",&pos);
elem = a[pos];
if (pos<=n && pos>=0)
{
for (i=pos; i<n; i++)
{
a[i]=a[i+1];
}
n--;
printf ("\n deleted element is =%d",elem);
}
}
}

main()
{
printf ("Program: Array operations 2\n Name: Manisha.K\n USN: 4SN21IS014");
do
{
printf ("\n Menu \n");
printf ("\n 1.create\n 2.display\n 3.insertion\n 4.delete\n 5.exit\n");
printf ("Enter your option\n");
scanf ("%d", &opt);
switch(opt)
{
case 1: create();
break;
case 2: display();
break;
case 3: insert();
break;
case 4: delete ();
break;
case 5: exit(0);
}
}while(1);
}

Dept. of ISE, SIT, Valachil Page 4


Data Structure and Applications (21CS32) 2022-2023

OUTPUT:

Figure 2

Figure 3

Dept. of ISE, SIT, Valachil Page 5


Data Structure and Applications (21CS32) 2022-2023

Module-2
Laboratory Component:

3. Design, Develop and Implement a menu driven Program in C for the

following operations on STACK of Integers (Array Implementation of Stack


with maximum size MAX)
a. Push an Element on to Stack
b. Pop an Element from Stack
c. Demonstrate Overflow and Underflow situations on Stack
d. Display the status of Stack
e. Exit

Support the program with appropriate functions for each of the above
operations.

CODE:
#include <stdlib.h>
#include <stdio.h>
#define MAX 5
int stack[MAX], top=-1, opt;
int IsFull() {
if (top==(MAX-1))
{
printf ("stack is overflow\n");
return 1;
}
else
return 0;
}

int IsEmpty () {
if (top==-1)
{
printf ("stack is underflow\n");
return 1;
} else
return 0;
}

void Push (int item) {


if (IsFull()==0)
{
stack[++top]=item;
}
}

Dept. of ISE, SIT, Valachil Page 6


Data Structure and Applications (21CS32) 2022-2023

void Pop()
{
if (IsEmpty()==0)
{
printf ("the popped element is %d",stack[top--]);
}
}

void Display()
{
int i;
if (IsEmpty()==0)
{
printf ("stack contents are\n");
for (i=top; i>=0; i--)
{
printf ("%d\t",stack[i]);
}
}
}

void main()
{
printf("Program: Stack operations \n Name: Manisha.K\n USN: 4SN21IS014");
int item;
do
{
printf ("\n Menu \n");
printf ("\n1.Push\n 2.Pop\n 3.display\n 4.Exit\n");
printf ("enter your option");
scanf ("%d",&opt);
switch (opt)
{
case 1: printf ("enter an element to a stack\n");
scanf("%d", &item);
Push (item);
break;
case 2: Pop();
break;
case 3: Display();
break;
case 4: exit(0);
break;
}
}
while(1);
}

Dept. of ISE, SIT, Valachil Page 7


Data Structure and Applications (21CS32) 2022-2023

OUTPUT:

Figure 4

Figure 5

Dept. of ISE, SIT, Valachil Page 8


Data Structure and Applications (21CS32) 2022-2023

Figure 6

Figure 7

Dept. of ISE, SIT, Valachil Page 9


Data Structure and Applications (21CS32) 2022-2023

Laboratory Component:

4. Design, Develop and Implement a Program in C for the following Stack


Applications
a. Evaluation of Suffix expression with single digit operands and operators: +,
-,*,/,%,^

CODE:
#include <stdio.h>
#include <math.h>
#include <string.h>
int compute (char symbol, int op1, int op2) {
int temp=1, i;
switch (symbol) {
case '+': temp= op1+ op2;
break;
case '-': temp= op1- op2;
break;
case '*': temp= op1* op2;
break;
case '/': if(op2!=0)
{
temp= op1/ op2;
break;
}
case '^': for(i=0;i<=op2;i++)
temp= temp*op1;
break;
default: break;
}
return temp;
}
void main() {
printf ("Program: Stack applications \n Name: Manisha.K\n USN: 4SN21IS014");
int i, s[20], op1, op2, top= -1;
char symbol, postfix[20];
printf ("enter the postfix expression");
scanf ("%s",postfix);
for(i=0; i<strlen(postfix); i++) {
symbol= postfix[i];
if (isdigit(symbol))
s[++top]=symbol-'0';
else {
op2= s[top--];
op1= s[top];
s[top]=compute(symbol,op1,op2);
}}
printf("the result is%d\n",s[top]);
}

Dept. of ISE, SIT, Valachil Page 10


Data Structure and Applications (21CS32) 2022-2023

OUTPUT:

Figure 8

Dept. of ISE, SIT, Valachil Page 11


Data Structure and Applications (21CS32) 2022-2023

Laboratory Component:

4. Design, Develop and Implement a Program in C for the following Stack


Applications
b. Solving Tower of Hanoi problem with n disks

CODE:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
void TOH (int n, char A, char B,char C) {
if (n>0)
{
TOH (n-1,A,C,B);
printf ("\nmove disc %d from %c to %c",n,A,C);
TOH (n-1,B,A,C);
}
}
void main(){
printf ("Program: Stack applications \n Name: Manisha.K\n USN: 4SN21IS014");
int n, A, B, C;
printf ("\nenter no. of disc");
scanf ("%d",&n);
TOH (n,'A','B','C');
}

OUTPUT:

Figure 9

Dept. of ISE, SIT, Valachil Page 12


Data Structure and Applications (21CS32) 2022-2023

Module-3
Laboratory Component:

5. Singly Linked List (SLL) of Integer Data


a. Create a SLL stack of N integer.
b. Display of SLL
c. Linear search.
Create a SLL queue of N Students Data Concatenation of two SLL of integers

CODE:

#include <stdio.h>
#include <stdlib.h>
int MAX=4;
struct SLL {
int data;
struct SLL*next;
};

typedef struct SLL NODE;


NODE * Getnode()
{
NODE * newnode = (NODE*) malloc (sizeof(NODE));
printf ("\n Enter data:");
scanf ("%d",&newnode->data);
newnode->next=NULL;
return (newnode);
}

void Display (NODE*p)


{
if (p!=NULL)
{
printf ("\n_____ DATA______\n");
while (p!=NULL)
{
printf ("%d\t",p->data);
p=p->next;
}
}
else
printf ("\n No data available!!\n");
}

NODE * Insert_Rear(NODE*head)
{
NODE * newnode,*p;
newnode = Getnode();
if (head==NULL)
head=newnode;
else

Dept. of ISE, SIT, Valachil Page 13


Data Structure and Applications (21CS32) 2022-2023

{
p=head;
while (p->next!=NULL)
{
p = p->next;
}
p -> next=newnode;
}
return(head);
}

NODE * Delete_Rear(NODE*head)
{
NODE*p,*q;
p=head;
if (head==NULL)
printf ("\n Empty(Underflow)");
else
{
if (head->next==NULL)
head=NULL;
else
{
while (p->next!=NULL)
{
q=p;
p= p->next;
}
q->next=NULL;
free(p);
}
}
return head;
}

NODE*Concatenate(NODE*head1,NODE*head2)
{
NODE*head3=head1,*p=head1;
Display(head1);
Display(head2);
while(p->next!=NULL)
{
p=p->next;
}
p->next=head2;
return(head3);
}
void Search(NODE*head1)
{
NODE*p=head1;
int flag=0,data;

Dept. of ISE, SIT, Valachil Page 14


Data Structure and Applications (21CS32) 2022-2023

printf("\n Enter data to be searched in SLL 1:");


scanf("%d",&data);
while(p!=NULL)
{

if (p->data==data)
{
flag=1;
printf("Data found");
}
p=p->next;
}
if(flag==0)
printf("Data not found");
}
int main()
{
printf("Program: Singly linked list \n Name: Manisha.K\n USN: 4SN21IS014");
int ch;
NODE*head1=NULL,*head2=NULL,*head3=NULL;
printf("\n DATA \n");
do{
printf("\n MENU: \n1.Create SLL1 \n2.Create SLL2 \n3.Display SLL-1 \n4.Display SLL-2 \
n5.SLL1-Stack 1- PUSH\n6.SLL1- Stack 1-POP\n7.Concatenate\n8.Search in SLL1\n9.Exit \n
Enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: head1=Insert_Rear(head1);
break;
case 2: head2=Insert_Rear(head2);
break;
case 3: Display(head1);
break;
case 4: Display(head2);
break;
case 5: head1= Insert_Rear(head1);
break;
case 6: head1= Delete_Rear(head1);
break;
case 7: head3= Concatenate(head1,head2);
printf("\n After concatenation:\n");
Display (head3);
break;
case 8: Search(head1);
break;
case 9: exit(0);
}
}
while(1);
}

Dept. of ISE, SIT, Valachil Page 15


Data Structure and Applications (21CS32) 2022-2023

OUTPUT:

Figure 10

Figure 11

Dept. of ISE, SIT, Valachil Page 16


Data Structure and Applications (21CS32) 2022-2023

Figure 12

Figure 13

Dept. of ISE, SIT, Valachil Page 17


Data Structure and Applications (21CS32) 2022-2023

Figure 14

Figure 15

Dept. of ISE, SIT, Valachil Page 18


Data Structure and Applications (21CS32) 2022-2023

Figure 16

Dept. of ISE, SIT, Valachil Page 19


Data Structure and Applications (21CS32) 2022-2023

Laboratory Component:

6. Design, Develop and Implement a menu driven Program in C for the


following operations on Doubly Linked List (DLL) of Professor Data with the
fields: ID, Name, Branch, Area of specialization
a. Create a DLL stack of N Professor’s Data
b. Create a DLL queue of N Professor’s Data
Display the status of DLL and count the number of nodes in it.

CODE:

#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>

int MAX=4,count=0;
struct Prof{
char ID[5], Name[20], Branch[5], Area[10];
struct Prof *left, *right;
};
typedef struct Prof NODE;
NODE * Getnode()
{
NODE* node= (NODE*) malloc (sizeof(NODE));
printf ("\n Enter ID, Name, Dept, Area of spl:");
scanf ("%s %s %s %s", node-> ID, node-> Name, node-> Branch, node-> Area);
node->right= node->left=NULL;
count ++;
return node;
}
void Display (NODE*p)
{
if (p!=NULL)
{
printf ("\n ID\t Name\t Branch\t Area");
while(p!=NULL)
{
printf ("\n%s\t%s\t%s\t%s ",p-> ID, p-> Name,p->Branch,p->Area);
p=p->right;
}
printf ("\n Number of nodes %d \n",count);
}
else
printf ("\n No data available!!");
}
NODE* Insert_Rear(NODE*head){
NODE* p= head, *newnode;
if (count==MAX)
printf ("\n Overflow!!");
else
{
newnode= Getnode();

Dept. of ISE, SIT, Valachil Page 20


Data Structure and Applications (21CS32) 2022-2023

if (head==NULL)
head =newnode;
else
{
while (p->right!=NULL)
{
p=p->right;
}
p-> right= newnode;
newnode->left=p;
}
}
return head;
}
NODE* Delete_Rear(NODE*head){
NODE* p=head,*q;
if (head==NULL)
printf ("\n list is empty(QUEUE)");
else {
while (p->right!=NULL){
p=p->right;
}
if (p->left!=NULL){
q= p->left;
q->right=NULL;
}
else
head=NULL;
free (p);
count--;
}
return head;
}
NODE* Delete_Front (NODE*head){
NODE* p=head,*q;
if (head==NULL)
printf ("\n list is empty(QUEUE)");
else
{
if (p->right==NULL)
head =NULL;
else {
head =p->right;
head->left=NULL;
}
free (p);
count--;
}
return head;
}

Dept. of ISE, SIT, Valachil Page 21


Data Structure and Applications (21CS32) 2022-2023

int main()
{
printf ("Program: Doubly linked list \n Name: Manisha.K\n USN: 4SN21IS014");
int ch,i;
NODE * head=NULL;
printf ("\n How many professors data you want to create:");
do{
printf ("\n 1.Display\n 2.Stack-PUSH\n 3.Stack-POP\n 4.Queue- Insert\n 5.Queue-Delete\n
6.EXIT");
printf ("\nenter your choice:");
scanf ("%d",&ch);
switch(ch)
{
case 1: Display(head);
break ;
case 2: head= Insert_Rear(head);
break;
case 3: head= Delete_Rear(head);
break;
case 4: head= Insert_Rear(head);
break;
case 5: head= Delete_Front(head);
break;
case 6: exit(0);
}
}
while(1);
}

OUTPUT:

Figure 17

Dept. of ISE, SIT, Valachil Page 22


Data Structure and Applications (21CS32) 2022-2023

Figure 18

Figure 19

Dept. of ISE, SIT, Valachil Page 23


Data Structure and Applications (21CS32) 2022-2023

Module-4
Laboratory Component:

7. Given an array of elements, construct a complete binary tree from this


array in level order fashion. That is, elements from left in the array will be
filled in the tree level wise starting from level 0. Ex: Input :
arr [] = {1, 2, 3, 4, 5, 6}
Output : Root of the following tree
1
/ \
2 3
/\ /\
4 5 6

CODE:

#include <stdio.h>
#include <stdlib.h>
struct CBTree
{
int data;
struct CBTree *left,*right;
};

typedef struct CBTree NODE;


NODE* newNode(int data){
NODE* node=(NODE*)calloc(1,sizeof(NODE));
node->data=data;
return(node);
}

NODE* insertLevelOrder(NODE*root,int arr[],int i,int n){


if (i<n){
root = newNode(arr[i]);
root->left=insertLevelOrder(root->left,arr,2*i+1,n);
root->right=insertLevelOrder(root->right,arr,2*i+2,n);
}
return root;
}

void inOrder(NODE* root){


if(root!=NULL){
inOrder(root->left);
printf("%d \t",root->data);
inOrder(root->right);
}
}

int main(){
printf("Program: Binary tree \n Name: Manisha.K\n USN: 4SN21IS014");
int arr[50], n=0, num;

Dept. of ISE, SIT, Valachil Page 24


Data Structure and Applications (21CS32) 2022-2023

NODE* root=NULL;
while (1){
printf ("enter number to insert to CBT:");
scanf ("%d",&arr[n]);
printf ("enter 0 to stop and 1 to continue..");
scanf ("%d",&num);
if (num==0)
break;
else
n++;
}
root=insertLevelOrder(root,arr,0,n+1);
inOrder(root);
}

OUTPUT:

Figure 20

Dept. of ISE, SIT, Valachil Page 25


Data Structure and Applications (21CS32) 2022-2023

Laboratory Component:

8. Design, Develop and Implement a menu driven Program in C for the


following operations on Binary Search Tree (BST) of Integers
a. Create a BST of N Integers
b. Traverse the BST in Inorder, Preorder and Post Order

CODE:

#include <stdio.h>
#include <stdlib.h>
struct BST{
int data;
struct BST* left, *right;
};
typedef struct BST NODE;
NODE * Createtree(NODE* node,int data) {
if (node==NULL) {
NODE*temp= (NODE*) calloc (1,sizeof(NODE));
temp->data=data;
return temp;
}
if (data<(node->data))
node->left= Createtree (node->left,data);
else if(data> node->data)
node->right= Createtree (node->right,data);
else
printf ("Duplicate data found");
return node;
}
NODE* Search (NODE* node,int data){
if (node==NULL)
printf ("Element not found");
else if (data<node->data)
node->left= Search(node->left,data);
else if (data>node->data)
node->right =Search (node-> right,data);
else
printf ("\n Element found: %d",node->data);
return node;
}
void Inorder (NODE*node){
if (node!=NULL) {
Inorder (node-> left);
printf ("%d\t",node->data);
Inorder (node-> right);
}
}
void Preorder (NODE*node) {
if (node!=0) {
printf ("%d\t",node->data);
Preorder (node-> left);

Dept. of ISE, SIT, Valachil Page 26


Data Structure and Applications (21CS32) 2022-2023

Preorder (node-> right);


}
}
void Postorder (NODE*node) {
if (node!=0) {
Postorder (node-> left);
Postorder (node-> right);
printf ("%d\t",node->data);
}
}
int main() {
int data,ch,i;
NODE*root=NULL;
printf (" Name: Manisha.K\n USN: 4SN21IS014\n Program: Binary Search tree ");
do {
printf ("\n1.Insertion BST \n 2.Search element in BST \n 3.Inorder \n 4.Preorder \n 5.Postorder \n
Exit \n");
printf ("Enter you choice");
scanf ("%d",&ch);
switch(ch) {
case 1:
while(1) {
printf ("Enter the data to insert");
scanf ("%d",&data);
root= Createtree (root,data);
printf ("enter 0 to stop and 1 to continue");
scanf ("%d",&ch);
if(ch==0)
break;
}
break;
case 2: printf ("Enter the element to search");
scanf ("%d",&data);
root= Createtree (root,data);
break;
case 3: printf ("\n Inorder traversal:\n");
Inorder (root);
break;
case 4: printf ("\n Inorder traversal:\n");
Preorder (root);
break;
case 5: printf ("\n Inorder traversal:\n");
Postorder (root);
break;
case 6: exit(0);
default: printf ("\n wrong option");
break;
}
}
while(1);
}

Dept. of ISE, SIT, Valachil Page 27


Data Structure and Applications (21CS32) 2022-2023

OUTPUT:

Figure 21

Figure 22

Dept. of ISE, SIT, Valachil Page 28


Data Structure and Applications (21CS32) 2022-2023

Figure 23

Figure 24

Dept. of ISE, SIT, Valachil Page 29


Data Structure and Applications (21CS32) 2022-2023

Module-5
Laboratory Component:

9. Design, Develop and implement a program in C for the following operations


on Graph (G) of cities
a. Create a Graph of N cities using Adjacency Matrix.
b. Print all the nodes reachable from a given starting node in a diagraph using
DFS/BFS method.

CODE:

#include <stdlib.h>
#include <stdio.h>
int adj[20][20], visited[20], G[20], front= -1, rear= -1, top= -1,n,i;
void BFS(int v){
int cur;
visited[v]=1;
G[++rear]=v;
while (front!=rear) {
cur=G[++front];
for (i=1; i<=n; i++) {
if ((adj[cur][i]==1)&&(visited[i]==0))
{
G[++rear]==i;
visited[i]=1;
printf("%d->%d\n", cur, i);
}
}
}
}
void DFS2 (int v){
int i;
top= -1;
visited[v]=1;
do {
i=1;
while (i<=n){
if(adj[v][i]==1&&visited[i]==0){
G[++top]==v;
visited[i]=1;
printf("%d-->%d", v, i);
v=i;
i=1;
}
else
i++;
}
v= G[top--];
}
while (top!=-1);
}

Dept. of ISE, SIT, Valachil Page 30


Data Structure and Applications (21CS32) 2022-2023

int main(){
int ch, start, i, j;
printf ("Program: GRAPH \n Name: Manisha.K\n USN: 4SN21IS014");
printf ("\n Enter the number of vertices in graph:");
scanf ("%d",&n);
printf ("\n enter the adjacency matrix:\n");
for (i=1; i<=n; i++)
for (j=1; j<=n; j++)
scanf ("%d",&adj[i][j]);
do{
printf ("\n1.BFS\n 2.DFS\n 3.exit");
printf ("enter your choice");
scanf ("%d",&ch);
for (i=1; i<=n; i++)
visited[i]=0;
printf ("enter the starting vertex");
scanf ("%d",&start);
printf ("\n Nodes reachable from starting vertex %d are",start);
switch (ch)
{
case 1: BFS(start);
break;
case 2: DFS2(start);
break;
case 3: exit(0);
}
}while(ch!=3);
}

OUTPUT:

Figure 25

Dept. of ISE, SIT, Valachil Page 31


Data Structure and Applications (21CS32) 2022-2023

Laboratory Component:

10. Design and develop a program in C that uses Hash Function H:K->L as
H(K)=K mod m(reminder method) and implement hashing technique to map
a given key K to the address space L. Resolve the collision (if any) using linear
probing.

CODE:
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define HTSIZE 10
#define KEYSPACE 50
struct employee
{
int id;
char name[15];
};
typedef struct employee EMP;
EMP emp[KEYSPACE];
EMP HashTable[HTSIZE];

void Linear_prob(EMP emp){


int flag=0, i=emp.id%HTSIZE,j=i;
do{
if(HashTable[j].id == -1){
flag=1;
HashTable[j].id=emp.id;
strcpy(HashTable[j].name,emp.name);
}
else
j=(j+1)%HTSIZE;
}while(flag==0 && i!=j);
if(flag==0)
printf ("Hash table is full, key is rejected!?");
else if(flag==1 && i==j)
printf ("\n Hash value generated , data is stored !!!\n");
else if(flag==1 && i!=j)
printf ("\n Collision detected and resolved using linear probing");
}

void Display(){
int i, ch;
printf("\n1.Display ALL\n2.Filtered Display \n Enter the choice:");
scanf("%d",&ch);
printf("\nHash Value\tEmpID\tEmpName");
switch (ch){
case 1:
for(i=0; i<HTSIZE; i++)
printf("\n%d\t\t%d\t%s", i, HashTable[i].id,
HashTable[i].name);

Dept. of ISE, SIT, Valachil Page 32


Data Structure and Applications (21CS32) 2022-2023

break;
case 2:
for(i=0; i<HTSIZE; i++)
{
if(HashTable[i].id == -1)
continue;
else
printf("\n%d\t\t%d\t%s", i, HashTable[i].id,
HashTable[i].name);
}
break;
}
}
int main()
{
printf ("Name: Manisha K\n");
printf ("USN:4SN21IS014\n");
printf("Program name: Hashing\n");
int i;
int ch = 1;
printf("\nCollision handling by linear probing: ");
for (i=0; i < HTSIZE; i++)
{
HashTable[i].id = -1;
}
i=0;
do{
printf("\nEnter emp id: ");
scanf("%d",&emp[i].id);
printf("\n Enter emp name: ");
scanf("%s",emp[i].name);
Linear_prob(emp[i]);
printf("\n Do you wish to continue? (1/0): ");
scanf("%d",&ch);
}
while(ch==1);
Display();
}

Dept. of ISE, SIT, Valachil Page 33


Data Structure and Applications (21CS32) 2022-2023

OUTPUT:

Figure 26

Figure 27

Dept. of ISE, SIT, Valachil Page 34


Data Structure and Applications (21CS32) 2022-2023

Figure 28

Figure 29

Dept. of ISE, SIT, Valachil Page 35


Data Structure and Applications (21CS32) 2022-2023

Figure 30

Figure 31

Dept. of ISE, SIT, Valachil Page 36


Data Structure and Applications (21CS32) 2022-2023

Dept. of ISE, SIT, Valachil Page 37

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy