0% found this document useful (0 votes)
51 views22 pages

Department of Computer Science & Engineering: Government S K S J Technological Insititute

The document contains code and instructions for several data structure programs in C including: 1. An array-based menu-driven program to perform operations like creation, insertion, deletion and display of array elements. 2. A stack implementation using arrays with functions for push, pop and display. Example applications include postfix expression evaluation and Tower of Hanoi problem. 3. A singly linked list implementation with functions for insertion, deletion, search and display. The functions demonstrate basic linked list operations.

Uploaded by

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

Department of Computer Science & Engineering: Government S K S J Technological Insititute

The document contains code and instructions for several data structure programs in C including: 1. An array-based menu-driven program to perform operations like creation, insertion, deletion and display of array elements. 2. A stack implementation using arrays with functions for push, pop and display. Example applications include postfix expression evaluation and Tower of Hanoi problem. 3. A singly linked list implementation with functions for insertion, deletion, search and display. The functions demonstrate basic linked list operations.

Uploaded by

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

GOVERNMENT S K S J TECHNOLOGICAL INSITITUTE

[AFFILIATED TO VISVESWARAIAH TECHNOLOGICAL UNIVERSITY]

K R CIRCLE.BENGALURU 560001

DEPARTMENT OF COMPUTER SCIENCE &


ENGINEERING
3rd Semester

DATA STRUCTURES AND APPLICATIONS


Subject Code: 21CS32

FACULTY INCHARGE:
Mrs. Anitha A C
ASSISTANT PROFESSOR
Department of CSE
GSKSJTI,Bangalore
MODULE 1 AND 2
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.
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.
#include<stdio.h>
#include<stdlib.h>
int a[20];
int n,val,i,pos;
/*Function Prototype*/
void create();
void display();
void insert();
void delete();
int main()
{
int choice=1;
while(choice)
{
printf("\n\n--------MENU ---------- \n");
printf("1.CREATE\n");
printf("2.DISPLAY\n");
printf("3.INSERT\n");
printf("4.DELETE\n");
printf("5.EXIT\n");
printf(" -----------------------");
printf("\nENTER YOUR CHOICE:\t");
scanf("%d",&choice);
switch(choice)
{
case 1:
create();
break;
case 2:
display();
break;
case 3:
insert();
break;
case 4:
delete();
break;
case 5:
exit(0);
default:
printf("\nInvalid choice:\n");
break;
}
}
return 0;
}
//creating an array
void create()
{
printf("\nEnter the size of the array elements:\t");
scanf("%d",&n);
printf("\nEnter the elements for the array:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
}
//displaying an array elements
void display()
{
int i;
printf("\nThe array elements are:\n");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
}
//inserting an element into an array
void insert()
{
printf("\nEnter the position for the new element:\t");
scanf("%d",&pos);
printf("\nEnter the element to be inserted :\t");
scanf("%d",&val);
for(i=n-1;i>=pos;i--)
{
a[i+1]=a[i];
}
a[pos]=val;
n=n+1;
}
//deleting an array element
void delete()
{
printf("\nEnter the position of the element to be deleted:\t");
scanf("%d",&pos);
val=a[pos];
for(i=pos;i<n-1;i++)
{
a[i]=a[i+1];
}
n=n-1;
printf("\nThe deleted element is =%d",val);
}
/*Output:

--------MENU-----------
1. CREATE
2. DISPLAY
3. INSERT
4. DELETE
5. EXIT
-----------------------
ENTER YOUR CHOICE: 1

Enter the size of the array elements: 4

Enter the elements for the array:


10 20 30 40

--------MENU-----------
1. CREATE
2. DISPLAY
3. INSERT
4. DELETE
5. EXIT
--------MENU-----------
1. CREATE
2. DISPLAY
3. INSERT
4. DELETE
5. EXIT
-----------------------
ENTER YOUR CHOICE: 2

The array elements are:


10 20 30 40

--------MENU-----------
1. CREATE
2. DISPLAY
3. INSERT
4. DELETE
5. EXIT
-----------------------
ENTER YOUR CHOICE: 3

Enter the position for the new element: 3

Enter the element to be inserted : 45

--------MENU-----------
1. CREATE
2. DISPLAY
3. INSERT
4. DELETE
5. EXIT
10 20 30 40

--------MENU-----------
1. CREATE
2. DISPLAY
3. INSERT
4. DELETE
5. EXIT
--------MENU-----------
1. CREATE
2. DISPLAY
3. INSERT
4. DELETE
5. EXIT
Enter the element to be inserted : 32

--------MENU-----------
1. CREATE
2. DISPLAY
3. INSERT
4. DELETE
5. EXIT
-----------------------

ENTER YOUR CHOICE: 4

Enter the position of the element to be deleted: 4

The deleted element is =40

--------MENU-----------
1. CREATE
2. DISPLAY
3. INSERT
4. DELETE
5. EXIT
-----------------------
ENTER YOUR CHOICE: 5
*/
MODULE 3 AND 4

1. 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
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#define max_size 5
int stack[max_size],top = -1;
void push();
void pop();
void display();
int main()
{
int choice;
clrscr();
while(choice)
{
printf("\n\n--------STACK OPERATIONS ---------- \n");
printf("1.Push\n");
printf("2.Pop\n");
printf("3.Display\n");
printf("4.Exit\n");
printf(" -----------------------");
printf("\nEnter your choice:\t");
scanf("%d",&choice);
switch(choice)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default:
printf("\nInvalid choice:\n");
break;
}
}
return 0;
}
void push() //Inserting element into the stack
{
int item,n;
if(top==(max_size-1))
{
printf("\nStack Overflow:");
}
else
{
printf("Enter the element to be inserted:\t");
scanf("%d",&item);
top=top+1;
stack[top]=item;
}
}
void pop() //deleting an element from the stack
{
int item;
if(top==-1)
{
printf("Stack Underflow:");
}
else
{
item=stack[top];
top=top-1;
printf("\nThe poped element: %d\t",item);
}
}
void display()
{
int i;
if(top==-1)
{
printf("\nStack is Empty:");
}
else
{
printf("\nThe stack elements are:\n" );
for(i=top;i>=0;i--)
{
printf("%d\n",stack[i]);
}
}
getch();
}

2. Design, Develop and Implement a Program in C for the following Stack Applications
a. Evaluation of Suffix expression with single digit operands and operators: +, -, *, /, %, ^
b. Solving Tower of Hanoi problem with n disks
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define MAX 50
int stack[MAX];
char post[MAX];
int top= -1;
/*fUNCTION PROTOYPE */
void pushstack(int tmp);
void calculator(char c);
void main()
{
int i;
clrscr();
printf("Insert a postfix notation :: ");
scanf("%s",post);
for(i=0;i<strlen(post);i++)
{
if(post[i]>='0' && post[i]<='9')
{
pushstack(i);
}
if(post[i]=='+' || post[i]=='-' || post[i]=='*' || post[i]=='/' || post[i]=='^')
{
calculator(post[i]);
}
}
printf("\n\nResult :: %d",stack[top]);
}
void pushstack(int tmp)
{
top++;
stack[top]=(int)(post[tmp]-48);
}
void calculator(char c)
{
int a,b,ans;
a=stack[top];
stack[top]='\0';
top--;
b=stack[top];
stack[top]='\0';
top--;
switch(c)
{
case '+':
ans=b+a;
break;
case '-':
ans=b-a;
break;
case '*':
ans=b*a;
break;
case '/':
ans=b/a;
break;
case '^':
ans=pow(b,a);
break;
default:
ans=0;
}
top++;
stack[top]=ans;
}
2 b. Solving Tower of Hanoi problem with n disks
#include <stdio.h>
void towers(int, char, char, char);
int main()
{
int num;
printf("Enter the number of disks : ");
scanf("%d", &num);
printf("The sequence of moves involved in the Tower of Hanoi are :\n");
towers(num, 'A', 'C', 'B');
return 0;
}
void towers(int num, char frompeg, char topeg, char auxpeg)
{
if (num == 1)
{
printf("\n Move disk 1 from peg %c to peg %c", frompeg, topeg);
return;
}
towers(num - 1, frompeg, auxpeg, topeg);
printf("\n Move disk %d from peg %c to peg %c", num, frompeg, topeg);
towers(num - 1, auxpeg, topeg, frompeg);
}
Module 5 and 6
1 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.
#include<stdio.h>
#include<conio.h>
/*Linked list declaration*/
struct node
{
int INFO;
struct node *NEXT;
};
struct node *FIRST = NULL;
struct node *LAST = NULL;
/*Declaring function prototypes for linked list operations*/
void insert(int);
int delete(int);
void print(void);
struct node *search (int);
void main()
{
int num1, num2, choice;
struct node *location;
/*Displaying a menu of choices for performing linked list operations*/
while(1)
{
clrscr();
printf("\nSelect an option\n");
printf("\n1 - Insert");
printf("\n2 - Delete");
printf("\n3 - Search");
printf("\n4 - Print");
printf("\n5 - Exit");
printf("\n\nEnter your choice:");
scanf("%d", &choice);
switch(choice)
{
case 1:
{
printf("\nEnter the element to be inserted into the linked list:");
scanf("%d",&num1);
insert(num1); /*Calling the insert() function*/
printf("\n%d successfully inserted into the linked list",num1);
getch();
break;
}
case 2:
{
printf("\nEnter the element to be deleted from the linked list:");
scanf("%d",&num1);
num2=delete(num1); /*Calling the delete() function */
if(num2==-9999)
printf("\n\t%d is not present in the linked list\n\t",num1);
else
printf("\n\tElement %d successfuly deleted from the linked list\n\t",num2);
getch();
break;
}
case 3:
{
printf("\nEnter the element to be searched:");
scanf("%d",&num1);
location=search(num1); /*Calling the search() function*/
if(location==NULL)
printf("\n\t%d is not present in the linked list\n\t",num1);
else
{
if(location==LAST)
printf("\n\tElement %d is the last element in the list",num1);
else
printf("\n\tElement %d is present before element %d in the linked list\
n\t",num1,(location->NEXT)->INFO);
}
getch();
break;
}
case 4:
{
print(); /*Printing the linked list elements*/
getch();
break;
}
case 5:
{
exit(1);
break;
}
default:
{
printf("\nIncorrect choice. Please try again.");
getch();
break;
}
}
}
}
/*Insert function*/
void insert(int value)
{
/*Creating a new node*/
struct node *PTR = (struct node*)malloc(sizeof(struct node));
/*Storing the element to be inserted in the new node*/
PTR->INFO = value;
/*Linking the new node to the linked list*/
if(FIRST==NULL)
{
FIRST = LAST = PTR;
PTR->NEXT=NULL;
}
else
{
LAST->NEXT = PTR;
PTR->NEXT = NULL;
LAST = PTR;
}
}
/*Delete function*/
int delete(int value)
{
struct node *LOC,*TEMP;
int i;
i=value;
LOC=search(i); /*Calling the search() function*/
if(LOC==NULL) /*Element not found*/
return(-9999);
if(LOC==FIRST)
{
if(FIRST==LAST)
FIRST=LAST=NULL;
else
FIRST=FIRST->NEXT;
return(value);
}
for(TEMP=FIRST;TEMP->NEXT!=LOC;TEMP=TEMP->NEXT)
;
TEMP->NEXT=LOC->NEXT;
if(LOC==LAST)
LAST=TEMP;
return(LOC->INFO);
}
/*Search function*/
struct node *search (int value)
{
struct node *PTR;
if(FIRST==NULL) /*Checking for empty list*/
return(NULL);
/*Searching the linked list*/
for(PTR=FIRST;PTR!=LAST;PTR=PTR->NEXT)
if(PTR->INFO==value)
return(PTR); /*Returning the location of the searched element*/
if(LAST->INFO==value)
return(LAST);
else
return(NULL); /*Returning NULL value indicating unsuccessful search*/
}
/*print function*/
void print()
{
struct node *PTR;
if(FIRST==NULL) /*Checking whether the list is empty*/
{
printf("\n\tEmpty List!!");
return;
}
printf("\nLinked list elements:\n");
if(FIRST==LAST) /*Checking if there is only one element in the list*/
{
printf("\t%d",FIRST->INFO);
return;
}
/*Printing the list elements*/
for(PTR=FIRST;PTR!=LAST;PTR=PTR->NEXT)
printf("\t%d",PTR->INFO);
printf("\t%d",LAST->INFO);
}
2. Design, Develop and Implement a menu driven Program in C for the following operations on
DoublyLinked 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.

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

struct node
{
int ID [25],
char name[25], Branch[25] Area of specialization;
struct node *llink;
struct node *rlink;
};
typedef struct node* NODE;

NODE first = NULL;


int count=0;

NODE create()
{
NODE enode;
enode = (NODE)malloc(sizeof(struct node));
if( enode== NULL)
{
printf("\nRunning out of memory");
exit(0);
}
printf("\nEnter the ID,Name,BAranch,area of specialization: \n");
scanf("%d %s %s %s", pnode->ID , pnode->name, pnode->Branch,pnode->Area of specialization);
enode->llink=NULL;
enode->rlink=NULL;
count++;
return enode;
}

NODE insertfront()
{
NODE temp;
temp = create();
if(first == NULL)
{
return temp;
}
temp->rlink = first;
first->llink = temp;
return temp;
}

void display()
{
NODE cur;
int nodeno=1;
cur = first;
if(cur == NULL)
printf("\nNo Contents to display in DLL");
while(cur!=NULL)
{
printf("\nPNode:%d||ID:%s|Name:%s|Branch:%sArea of specialization:%s”,nodeno, cur->ID, cur-
>name,cur->Branch, cur->area of specialization);
cur = cur->rlink;
nodeno++;
}
printf("\nNo ofProfessor nodes is %d",count);
}

NODE deletefront()
{
NODE temp;
if(first == NULL)
{
printf("\nDoubly Linked List is empty");
return NULL;
}
if(first->rlink== NULL)
{
printf("\nTheProfessor node with the ID:%s is deleted", first->ID);
free(first);
count--;
return NULL;
}
temp = first;
first = first->rlink;
temp->rlink = NULL;
first->llink = NULL;
printf("\nTheProfessor node with the ID:%s is deleted",temp->ID);
free(temp);
count--;
return first;
}

NODE insertend()
{
NODE cur, temp;
temp = create();

if(first == NULL)
{
return temp;
}
cur= first;
while(cur->rlink!=NULL)
{
cur = cur->rlink;
}

cur->rlink = temp;
temp->llink = cur;
return first;
}

NODE deleteend()
{
NODE prev,cur;
if(first == NULL)
{
printf("\nDoubly Linked List is empty");
return NULL;
}

if(first->rlink == NULL)
{
printf("\nTheProfessor node with the ID:%s is deleted",first->ID);
free(first);
count--;
return NULL;
}

prev=NULL;
cur=first;

while(cur->rlink!=NULL)
{
prev=cur;
cur = cur->rlink;
}
cur->llink = NULL;
printf("\nTheProfessor node with the ID:%s is deleted",cur->ID);
free(cur);
prev->rlink = NULL;
count--;
return first;
}

void deqdemo()
{
int ch;
while(1)
{
printf("\nDemo Double Ended Queue Operation");
printf("\n1:InsertQueueFront\n 2: DeleteQueueFront\n 3:InsertQueueRear\n 4:DeleteQueueRear\n
5:DisplayStatus\n 6: Exit \n");
scanf("%d", &ch);

switch(ch)
{
case 1: first=insertfront();
break;
case 2: first=deletefront();
break;
case 3: first=insertend();
break;
case 4: first=deleteend();
break;
case 5: display();
break;
default : return;
}
}
}

void main()
{
int ch,i,n;
while(1)
{
printf("\n\n~~~Menu~~~");
printf("\n1:Create DLL ofProfessor Nodes");
printf("\n2:DisplayStatus");
printf("\n3:InsertAtEnd");
printf("\n4:DeleteAtEnd");
printf("\n5:InsertAtFront");
printf("\n6:DeleteAtFront");
printf("\n7:Double Ended Queue Demo using DLL");
printf("\n8:Exit \n");
printf("\nPlease enter your choice: ");
scanf("%d",&ch);

switch(ch)
{
case 1 : printf("\nEnter the no ofProfessors: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
first = insertend();
break;

case 2: display();
break;

case 3: first = insertend();


break;

case 4: first = deleteend();


break;

case 5: first = insertfront();


break;

case 6: first = deletefront();


break;

case 7: deqdemo();
break;

case 8 : exit(0);
default: printf("\nPlease Enter the valid choice");
}
}
}

Module 7 and 8
2. 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
#include <stdio.h>
#include <stdlib.h>
int flag=0;
typedef struct BST
{
int data;
struct BST *lchild,*rchild;
} node;
/*FUNCTION PROTOTYPE*/
void insert(node *, node *);
void inorder(node *);
void preorder(node *);
void postorder(node *);
node *search(node *, int, node **);
void main()
{
int choice;
int ans =1;
int key;
node *new_node, *root, *tmp, *parent;
node *get_node();
root = NULL;
clrscr();
printf("\nProgram For Binary Search Tree ");
do
{
printf("\n1.Create");
printf("\n2.Search");
printf("\n3.Recursive Traversals");
printf("\n4.Exit");
printf("\nEnter your choice :");
scanf("%d", &choice);
switch (choice)
{
case 1:
do
{
new_node = get_node();
printf("\nEnter The Element ");
scanf("%d", &new_node->data);
if (root == NULL) /* Tree is not Created */
root = new_node;
else
insert(root, new_node);
printf("\nWant To enter More Elements?(1/0)");
scanf("%d",&ans);
} while (ans);
break;
case 2:
printf("\nEnter Element to be searched :");
scanf("%d", &key);
tmp = search(root, key, &parent);
if(flag==1)
{
printf("\nParent of node %d is %d", tmp->data, parent->data);
}
else
{
printf("\n The %d Element is not Present",key);
}
flag=0;
break;
case 3:
if (root == NULL)
printf("Tree Is Not Created");
else
{
printf("\nThe Inorder display :");
inorder(root);
printf("\nThe Preorder display : ");
preorder(root);
printf("\nThe Postorder display : ");
postorder(root);
}
break;
}
}
while (choice != 4);
}
/*Get new Node */
node *get_node()
{
node *temp;
temp = (node *) malloc(sizeof(node));
temp->lchild = NULL;
temp->rchild = NULL;
return temp;
}
/*This function is for creating a binary search tree */
void insert(node *root, node *new_node)
{
if (new_node->data < root->data)
{
if(root->lchild==NULL)
root->lchild=new_node;
else
insert(root->lchild, new_node);
}
if (new_node->data > root->data)
{
if (root->rchild == NULL)
root->rchild = new_node;
else
insert(root->rchild, new_node);
}
}
/*This function is for searching the node from binary Search Tree*/
node *search(node *root, int key, node **parent)
{
node *temp;
temp = root;
while (temp != NULL)
{
if (temp->data == key)
{
printf("\nThe %d Element is Present", temp->data);
flag=1;
return temp;
}
*parent = temp;
if (temp->data > key)
temp = temp->lchild;
else
temp = temp->rchild;
}
return NULL;
}
/*This function displays the tree in inorder fashion */
void inorder(node *temp)
{
if (temp != NULL)
{
inorder(temp->lchild);
printf("%d\t", temp->data);
inorder(temp->rchild);
}
}
/*This function displays the tree in preorder fashion */
void preorder(node *temp)
{
if (temp != NULL)
{
printf("%d\t", temp->data);
preorder(temp->lchild);
preorder(temp->rchild);
}
}
/*This function displays the tree in postorder fashion */
void postorder(node *temp)
{
if (temp != NULL)
{
postorder(temp->lchild);
postorder(temp->rchild);
printf("%d\t", temp->data);
}
}

Module 9 and 10
1. 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.
#include<stdio.h>
#include<stdlib.h>

int a[50][50], n, visited[50];


int q[20], front = -1,rear = -1;
int s[20], top = -1, count=0;

void bfs(int v)
{
int i, cur;
visited[v] = 1;
q[++rear] = v;
while(front!=rear)
{
cur = q[++front];
for(i=1;i<=n;i++)
{
if((a[cur][i]==1)&&(visited[i]==0))
{
q[++rear] = i;
visited[i] = 1;
printf("%d ", i);
}
}
}
}

void dfs(int v)
{
int i;
visited[v]=1;
s[++top] = v;
for(i=1;i<=n;i++)
{
if(a[v][i] == 1&& visited[i] == 0 )
{
printf("%d ", i);
dfs(i);
}
}
}

int main()
{

int ch, start, i,j;


printf("\nEnter the number of vertices in graph: ");
scanf("%d",&n);
printf("\nEnter the adjacency matrix:\n");
for(i=1; i<=n; i++)
{
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
}

for(i=1;i<=n;i++)
visited[i]=0;
printf("\nEnter the starting vertex: ");
scanf("%d",&start);

printf("\n==>1. BFS: Print all nodes reachable from a given starting node");
printf("\n==>2. DFS: Print all nodes reachable from a given starting node");
printf("\n==>3:Exit");
printf("\nEnter your choice: ");
scanf("%d", &ch);
switch(ch)
{
case 1: printf("\nNodes reachable from starting vertex %d are: ", start);
bfs(start);
for(i=1;i<=n;i++)
{
if(visited[i]==0)
printf("\nThe vertex that is not reachable is %d" ,i);
}
break;

case 2: printf("\nNodes reachable from starting vertex %d are:\n",start);


dfs(start);
break;
case 3: exit(0);
default: printf("\nPlease enter valid choice:");
}
}

2. 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
#include<stdio.h>
#include<stdlib.h>

int key[20],n,m;
int *ht,index;
int count = 0;

void insert(int key)


{
index = key % m;
while(ht[index] != -1)
{
index = (index+1)%m;
}
ht[index] = key;
count++;
}

void display()
{
int i;
if(count == 0)
{
printf("\nHash Table is empty");
return;
}

printf("\nHash Table contents are:\n ");


for(i=0; i<m; i++)
printf("\n T[%d] --> %d ", i, ht[i]);
}

void main()
{
int i;
printf("\nEnter the number ofProfessor records (N) : ");
scanf("%d", &n);

printf("\nEnter the two digit memory locations (m) for hash table: ");
scanf("%d", &m);

ht = (int *)malloc(m*sizeof(int));
for(i=0; i<m; i++)
ht[i] = -1;

printf("\nEnter the four digit key values (K) for NProfessor Records:\n ");
for(i=0; i<n; i++)
scanf("%d", &key[i]);

for(i=0;i<n;i++)
{
if(count == m)
{
printf("\n~~~Hash table is full. Cannot insert the record %d key~~~",i+1);
break;
}
insert(key[i]);
}

//Displaying Keys inserted into hash table


display();
}

You might also like