Beruflich Dokumente
Kultur Dokumente
_ _
ð_7___ミ 3____________________ __Š
/* Write a program in C implement the insertion sort algorithm*/
#include <stdio.h>
main()
{
int c,i,j,n,v[50];
printf("Program for insertion sort\n\n");
printf("Enter element(-0 to exit):");
scanf("%d",&n);
c=0;
while(n!=-0)
{
j=c-1;
while((n<v[j]&&(j>=0)))
{
v[j+1]=v[j];
-j;
}
v[j+1] = n;
OUTPUT:
.pa_ _
`_-___ミ 3____________________ __Š /*Write a program in C for
addition,subtraction,
_
_ ú_ú_ _
__multiplication and division of elements of two arrays*/
#include <stdio.h>
main()
{
int i, num, option;
float arr1[50], arr2[50], arr3[50];
}
}
while(option!=0);
}
.pa_ _
ミ_!___ミ 3____________________ __Š
OUTPUT:
Choice Option
0 : Exit
1 : Summation
2 : Subraction
3 : Multiplication
4 : Division
Enter your option:1
Choice Option
0 : Exit
1 : Summation
2 : Subraction
3 : Multiplication
4 : Division
Enter your option:3
#include <stdio.h>
#include <malloc.h>
struct node
{
int item;
struct node *right, *left;
};
void main()
{
struct node *root, *last;
int new_item, posn, quit;
char c;
struct node *create();
void insert();
void delete();
void display();
do
{
printf("\n\tOptions\t\tChoice");
printf("\n\tCreate\t\tC");
printf("\n\tInsert\t\tI");
printf("\n\tDelete\t\tD");
printf("\n\tExit\t\tE");
printf("\n\tEnter choice:");
do
c=getchar();
while (strchr("CcIiDdEe",c) == NULL);
switch(c)
{
case 'c':
case 'C':
root = create(&last);
printf("*** Doubly Linked list ***\n");
display(root,last);
break;
case 'i':
case 'I':
printf("\n Enter the element to be
insertd :");
scanf("%d", &new_item);
do
{
printf("\nEnter the position of
insertion:");
scanf("%d",&posn);
}_ _
ð_7___ミ 3____________________ __Š while(posn < 1);
insert(&root, &last,
ヘ
new_item, posn);
printf("*** Doubly linked list ***\n");
display(root, last);
break;
case 'd':
case 'D':
delete(&root, &last);
printf("*** Doubly Linked list ***\n");
display(root, last);
break;
case 'e':
case 'E':
quit = 1;
}
}
while(!quit);
printf("\n");
}
_ _
ð_7___ミ 3____________________ __Š if(new_node->right == NULL)
*last=new_node;
}
if(*start != NULL)
{
if((*start)->item == element)
{
if((*start)->right == NULL)
*start=*last=NULL;
else
{
*start = (*start)->right;
(*start)->left = NULL;
}
}
else
{
temp=*start;
prec=NULL;
while((temp->right != NULL) &&
(temp->item != element))
{
prec=temp;
temp=temp->right;
}
if(temp->item != element)
printf("Element not found\n");
else
{
if(temp == *last)
*last=prec;
else
temp->right->left = temp->left;
prec->right = temp->right;
}
}
}
else
printf("\n Empty list ...\n");
return;
}
_ _
ð_7___ミ 3____________________ __Š OUTPUT:
Options Choice
Create C
Insert I
Delete D
Exit E
Enter choice:C
Options Choice
Create C
Insert I
Delete D
Exit E
Enter choice:I
Options Choice
Create C
Insert I
Delete D
Exit E
Enter choice:D
Element to be deleted:20
.pa_ _
°_3___ミ 3____________________ __Š
/*Write a program in C to illustrate the implementation of
_
_ *_*_ _
__circularly linked lists showing the function create() creates a
_
_ *_*_ _
__circularly linked list and the functions display(),insert() and
_
_ __ _
__delete() have the usual meanings.*/
#include <stdio.h>
#include <malloc.h>
struct node
{
int item;
struct node *next;
};
struct node *create(last)
struct node **last;
{
struct node *root, *new;
int temp, size;
size = sizeof(struct node);
printf("Enter an integer (-9999 to end) :");
scanf("%d",&temp);
*last = root = NULL;
while(temp != -9999)
{
new = (struct node *) malloc(size);
new->item = temp;
if(root == NULL)
root = new;
else
(*last)->next = new;
(*last) = new;
printf("Enter an integer (-9999 to end) :");
scanf("%d", &temp);
}
if(root != NULL)
new->next = root;
return root;
}
{
printf("\nRoot->");
if(start != NULL)
{
do
{
printf("%d->",start->item);
start = start->next;
}
_ _
ð_7___ミ 3____________________ __Š
while(last->next != start);
printf("Root\n");
}
else
printf("NULL\n");
}
if(*start != NULL)
if(posn == 1)
{
if((*start)->next != *start)
{
*start = (*start)->next;
(*last)->next = *start;_ _
ð_7___ミ 3____________________ __Š
}
else
*start = *last = NULL;
}
else
{
temp = *start;
i=2;
while((temp->next != (*start)) && (i<posn))
{
temp = temp->next;
++i;
}
if(temp->next != *start)
{
if(temp->next == *last)
*last = temp;
temp->next = temp->next->next;
}
else
return_value = 0;
}
else
return_value = 0;
return return_value;
}
void main()
{
struct node *root, *last;
int new_item, posn, quit;
char c;
_ _
ð_7___ミ 3____________________ __Š
OUTPUT:
Options Choice
Create C
Insert I
Delete D
Exit E
Ente choice :C
Enter an integer (-9999 to end) :10
Enter an integer (-9999 to end) :20
Enter an integer (-9999 to end) :-9999
Root->10->20->Root
Options Choice
Create C
Insert I
Delete D
Exit E
Ente choice :I
Root->30->10->20->Root
Options Choice
Create C
Insert I
Delete D
Exit E
Ente choice :D
Enter he position of deletion :2
Root->30->20->Root
.pa_ _
p_/___ミ 3____________________ __Š
#include <stdio.h>
int first, check;
void main()
{
int stack[10], element, quit;
char c;
int pop();
void push();
void display();
_ _
ð_7___ミ 3____________________ __Š
else
printf("\n Stack overflow...
don't push\n");
break;
case 'O':
case 'o':
element = pop(stack);
if(check)
{
printf("Popped element = %dn",element);
printf("\n\t *** Stack ****\n");
display(stack);
}
else
printf("Stack underflow...don't pop");
break;
case 'E':
case 'e':
quit = 1;
}
}
while(!quit);
printf("\n");
}
_ _
ð_7___ミ 3____________________ __Š
void display(stack)
int stack[];
{
int i;
if(first == -1)
printf("\n **** Empty ****\n");
else
{
for(i=first;i>=0;--i)
printf("%7d",stack[i]);
}
printf("\n");
}
int pop(stack)
int stack[];
{
int srs;
if(first == -1)
{
srs = 0;
check = 0;
}
else
{
check = 1;
srs = stack[first];
--first;
}
return srs;
}
.pa_ _
_"___ミ 3____________________ __Š OUTPUT:
Options Choice
Push P
Pop O
Exit E P
Options Choice
Push P
Pop O
Exit EP
Options Choice
Push P
Pop O
Exit EO
Popped element = 20
.pa_ _
ミ_!___ミ 3____________________ __Š
/*Write a program in C for implementation of stacks using
_
_ d_d_ _
__linked lists*/
#include <stdio.h>
#include <malloc.h>
struct node
{
int element;
struct node *next;
};
void main()
{
struct node *start;
int quit;
char c;
struct node *push();
struct node *pop();
void display();
printf("Program of stack with linked list\n");
start= NULL;
quit=0;
do
{
printf("\n\tOptions\t\tChoice");
printf("\n\tPush\t\tP");
printf("\n\tPop\t\tO");
printf("\n\tExit\t\tE");
printf("\n\tEnter choice:");
do
c=getchar();
while(strchr("PpOoEe",c) == NULL);
switch(c)
{
case 'P':
case 'p':
start=push(start);
printf("\n\t *** Stack ***\n");
display(start);
break;
case 'O':
case 'o':
start=pop(start);
printf("\n\t *** Stack ***\n");
display(start);
break;
case 'E':
case 'e':
quit = 1;
break;
}
}_ _
ð_7___ミ 3____________________ __Š
while(!quit);
printf("\n");
}
{
struct node *temp;
int element;
if(first == NULL)
printf("\n *** Empty ***\n");
else
{
printf("Popped element = %d", first->element);
temp = first->next;
free(first);
first=temp;
if(first == NULL)
printf("\n *** Empty ***\n");
}
return(first);
}
_ _
ð_7___ミ 3____________________ __Š
OUTPUT:
Options Choice
Push P
Pop O
Exit E
Enter choice:P
Enter an element to be pushed :10
Root-> 10->NULL
Options Choice
Push P
Pop O
Exit E
Enter choice:P
Enter an element to be pushed :20
Options Choice
Push P
Pop O
Exit E
Enter choice:O
Popped element = 20
Root-> 10->NULL
.PA_ _
__(___ミ 3____________________ __Š
/* Write a program in C for implementation ofstack operations*/
#include <stdio.h>
#define MAX 50
enum boolean
{
true = 1, false = 0, negone = -1
};
if(prs == MAX)
return false;
si = prs + ch;
if(si >= MAX || si < prs)
return negone;
*s = stack[si];
return true;
}
_ _
ð_7___ミ 3____________________ __Š
enum boolean change (stack, prs, s, ch)
int prs, ch;
char stack[MAX], s;
{
int si;
if(prs == MAX)
return false;
si = prs + ch;
if(si >= MAX || si <prs)
return negone;
stack[si] = s;
return true;
}
do
{
printf("\n\tOptions\t\tChoice");
printf("\n\tPush\t\tU");
printf("\n\tPop\t\tO");
printf("\n\tPeep\t\tP");
printf("\n\tEmpty\t\tM");
_ _
ð_7___ミ 3____________________ __Š
printf("\n\tChange\t\tC");
printf("\n\tExit\t\tE");
printf("\n\tEnter choice: ");
do
c=getchar();
while(strchr("UuOoPpMmCcEe",c) == NULL);
fflush (stdin);
switch(c)
{
case 'U':
case 'u':
printf("\n Enter an element to be
pushed:");
s=getc(stdin);
if(push(stack,&prs,s) == false)
printf("Stack Full\n");
diprslay(stack,prs);
break;
case 'O':
case 'o':
if(pop(stack, &prs, &s) == true)
printf("Popped element =%c\n",s);
else
printf("\n\t *** Empty ***\n");
diprslay(stack,prs);
break;
case 'P':
case 'p':
printf("\n Enter an index into stack:");
scanf("%d",&ch);
flag = peep(stack, prs, &s, ch);
if(flag == false)
printf("\n\t *** Empty *** \n");
else
if(flag == negone)
printf("Index not exist\n");
else
printf("Element at %d = %c\n",
ch,s);
diprslay(stack, prs);
break;
case 'M':
case 'm':
printf("Do you want empty stack(Y/N)?");
s=getc(stdin);
if (s == 'Y' || s == 'y')
{
prs = MAX;
printf("\n\t *** Empty ***\n");
}
diprslay(stack,prs);
break;
_ _
ð_7___ミ 3____________________ __Š
case 'C':
case 'c':
printf("\nEnter the index into stack:");
scanf ("%d",&ch);
fflush (stdin);
printf("\nEnter the value to be put:");
s=getc(stdin);
flag = change(stack, prs, s, ch);
if(flag == false)
printf("\n\t *** Empty ***\n");
else
if(flag == negone)
printf("Index not exist\n");
diprslay(stack, prs);
break;
case 'E':
case 'e':
quit = 1;
}
}
while (!quit);
printf("\n");
}
_ _
ð_7___ミ 3____________________ __Š
OUTPUT:
Options Choice
Push U
Pop O
Peep P
Empty M
Change C
Exit E
Enter choice: U
Options Choice
Push U
Pop O
Peep P
Empty M
Change C
Exit E
Enter choice: U
#include <stdio.h>
int first, last, check, count = 0;
void main()
{
int queue[10], element, quit;
char c;
void insert();
void delete();
void display();
printf("Program of queue with array\n");
last = first = quit = 0;
do
{
check = 1;
printf("\n\tOptions\t\tChoice");
printf("\n\tInsert\t\tI");
printf("\n\tDelete\t\tD");
printf("\n\tExit\t\tE");
printf("\n\tEnter choice :");
do
c = getchar ();
while(strchr("IiDdEe",c) == NULL);
switch(c)
{
case 'I':
case 'i':
printf("Enter an element to be inserted");
scanf("%d", &element);
insert(queue,element);
if(!check)
{
printf("*** Queue ***");
display(queue);
}
break;
case 'D':
case 'd':
delete(queue);
if((!check) && (count))
{
printf("*** Queue ***");
display(queue);
}
break;
case 'E':
case 'e':
quit = 1;
}
}
while(!quit);
printf("\n");_ _
ð_7___ミ 3____________________ __Š
void insert(queue, element)
int queue[10], element;
{
if(last<10)
{
last++;
queue[last] = element;
if(!first)
first = 1;
check = 0;
count++;
}
else
{
printf("Queue overflow ... don't insert\n");
check = 1;
}
return;
}
void display(queue)
int queue[10];
{
int c;
for(c=first;c<last+1;c++)
printf("%6d", queue[c]);
printf("\n");
return;
}
void delete(queue)
int queue[10];
{
int element;
if(first)
{
element = queue[first];
check = 0;
count--;
printf("Element deleted = %d\n", element);
if(first == last)
{
first = 0;
last = 0;
printf("\n\t *** Empty *** \n");
}
else
first++;
}
else
{
printf("Queue underflow ... don't delete\n");
check = 1;
}
return;
}_ _
ð_7___ミ 3____________________ __Š
OUTPUT:
Options Choice
Insert I
Delete D
Exit E
Enter choice :I
Options Choice
Insert I
Delete D
Exit E
Enter choice :I
Insert I
Delete D
Exit E
Enter choice :I
Options Choice
Insert I
Delete D
Exit E
Enter choice :D
Element deleted = 10
*** Queue ***
20
.PA_ _
` .___ミ 3____________________ __Š
/*Write a program in C for implementation of QUEUES
_
_ °_°_ _
__using pointers*/
#include <stdio.h>
#include <malloc.h>
struct node
{
int element;
struct node *next;
};
void main()
{
struct node *first = NULL, *last = NULL;
int quit,new_element;
char c;
void insert();
void delete();
void display();
void insert(first,last,i)
struct node **first, **last;
int i;
{
struct node *new_node;
new_node = (struct node *)malloc(sizeof(struct node));
new_node->element = i;
new_node->next = NULL;
if((*first) == NULL)
{
(*first) = new_node;
(*last) = new_node;
}
else
{
(*last)->next = new_node;
(*last) = new_node;
}
return;
}
void display(record)
struct node *record;
{
printf("\n Root");
while(record != NULL)
{
printf("-> %d", record->element);
record = record->next;
}
printf("->NULL\n");
return;
}
void delete(first)
struct node **first;
{
struct node *temp;
if((*first)!=NULL)
{
temp = *first;
(*first) = (*first)->next;
free(temp);
}
return;
}_ _
ð_7___ミ 3____________________ __Š
OUTPUT:
Options Choice
Insert I
Delete D
Exit E
Enter choice :I
Root-> 10->NULL
Options Choice
Insert I
Delete D
Exit E
Enter choice :I
Options Choice
Insert I
Delete D
Exit E
Enter choice :D
Root-> 20->NULL
.PA_ _
__(___ミ 3____________________ __Š
#include <stdio.h>
#include <malloc.h>
struct node
{
int element;
struct node *next;
};
void main()
{
struct node *first = NULL, *last = NULL;
int quit,new_element;
char c;
void insert();
void delete();
void display();
_ _
ð_7___ミ 3____________________ __Š
case 'D':
case 'd':
delete(&first,&last);
printf("\n\t *** Queue *** \n");
display(first);
break;
case 'E':
case 'e':
quit = 1;
}
}
while(!quit);
printf("\n");
}
void insert(first,last,i)
struct node **first, **last;
int i;
{
struct node *new_node;
new_node = (struct node *)malloc(sizeof(struct node));
new_node->element = i;
if((*first) == NULL)
{
(*first) = new_node;
(*last) = new_node;
}
else
{
(*last)->next = new_node;
(*last) = new_node;
}
new_node->next = *first;
return;
}
void display(record)
struct node *record;
{
struct node *temp;
temp = record;
printf("\n Root");
if(record != NULL)
{
_ _
ð_7___ミ 3____________________ __Š
do
{
printf("-> %d", record->element);
record = (record->next);
}
while(record!= temp);
printf("->Root\n");
}
else
printf("NULL\n");
return;
}
void delete(first,last)
struct node **first, **last;
{
struct node *temp;
if((*first)!= (*last))
{
temp = *first;
(*first) = (*first)->next;
(*last)->next = *first;
free(temp);
}
else
{
if((*first) != NULL)
free(*first);
(*first) = NULL;
(*last) = NULL;
}
return;
}
.pa_ _
0
+___ミ 3____________________ __Š OUTPUT:
Options Choice
Insert I
Delete D
Exit E
Enter choice :I
Root-> 10->Root
Options Choice
Insert I
Delete D
Exit E
Enter choice :I
Options Choice
Insert I
Delete D
Exit E
Enter choice :D
Root-> 20->Root
.pa_ _
ð_'___ミ 3____________________ __Š /*Write a program in C to test whether a given
word is
_
_ ¢_¢_ _
__palindrome or not*/
main()
{
int i, j;
char word[10];
printf("Enter a word to test for palindrome feature-->");
scanf("%s",word);
i = strlen(word);
i --;
j = 0;
while (j<= i)
{ if (word[i] != word[j])
{
printf("\nThe given word %s is not a palindrome \n", word);
goto ending;
}
i --;
j ++;
}
printf("\nThe given word %s is a palindrome \n", word);
ending : printf("\n\n");
}
.pa_ _
______ミ 3____________________ __Š OUTPUT:
.pa_ _
ð-____ミ 3____________________ __Š
_
_ „_„_ _
__/Dsp19- Writ a program in C to convert a given string of small
_
_ j
j
_
__letters into capital letters*/
#include<stdio.h>
main()
{
char str[20],I;
int i,k;
printf("Enter a word-->");
scanf("%s",str);
k=strlen(str);
printf("Before conversion the string is %s \n", str);
for (i=0;i<k;i++)
{
if(str[i]>='a'&&str[i]<='z')
str[i]=str[i]-32;
}
printf("After conversion the string is %s \n", str);
}
.pa_ _
Ð ____ミ 3____________________ __Š OUTPUT:
Enter a word-->hello
Before conversion the string is hello
After conversion the string is HELLO
.pa_ _
à.____ミ 3____________________ __Š
/*Write a program in C for addition,subtraction and
_
_ _
_
_
__multiplication of two matrices*/
# include <stdio.h>
main()
{
int i, j, k, l, m, n, o, option;
int mat1[50][50], mat2[50][50], mat3[50][50];
}
while(option!=0);
}_ _
ð_7___ミ 3____________________ __Š
OUTPUT:
Program for operations on matrix
Enter row and column of 1st matrix (1 to 50, 1 to 50) :2
2
Enter 4 element of 1st Matrix
1
2
3
4
Choice Option
0 : Exit
1 : Summation
2 : Subraction
3 : Multiplication
Enter your option:3
*** Matrix 1 ***
1 2
3 4
*** Matrix 2 ***
1 0
0 1
*** Result ***
1 2
3 4
.PA_ _
À_4___ミ 3____________________ __Š
_
_ T_T_
__/*Dsp21-Write a program in C for operation on trees*/
#include <stdio.h>
#include <malloc.h>
typedef struct tree
{
int item;
struct tree *left, *right;
}tree;
{
if(!p)
{
p=(tree*)malloc(sizeof(tree));
p->item=item;
p->left=NULL;
p->right=NULL;
return(p);
}
if(item < p->item)
p->left = insert(item, p->left);
else
if(item > p->item)
p->right = insert(item, p->right);
return(p);
}
if(temp)
{
output(temp->right, level+1);
printf("\n");
for(i=0;i<level;i++)
printf(" ");
printf("%d",temp->item);
output(temp->left, level+1);
}
}
_ _
ð_7___ミ 3____________________ __Š
tree *repl(s,p)
tree *s, *p;
{
tree *data;
if(s->right != NULL)
s->right = repl(s->right, p);
else
{
data = s;
p->item = s->item;
s=s->left;
free(data);
}
return(s);
}
tree *del(p,item)
tree *p;
int item;
{
tree *s;
if(!p)
{
printf(p);
}
else
{
if(item < p->item)
p->left = del (p->left, item);
else
if(item > p->item)
p->right = del(p->right, item);
_ _
ð_7___ミ 3____________________ __Š
else
{
s=p;
if(s->right == NULL)
{
p= s->left;
free(s);
}
}
if(s->left == NULL)
{
p=s->right;
free(s);
}
else
s->left = repl(s->left,s);
}
return(p);
}
void main()
{
int item,depth,quit=0 ;
char c;
tree *temp = NULL;
printf("Program for operations of tree \n");
do
{
printf("\n\tOptions\t\t\tChoice");
printf("\n\tInsert\t\tI");
printf("\n\tDelete\t\tD");
printf("\n\tExit\t\tE");
printf("\n\tEnter choice :");
do
c=getchar();
while(strchr("IiDdEe",c) == NULL);
_ _
ð_7___ミ 3____________________ __Š
switch(c)
{
case 'I':
case 'i':
printf("Enter element :");
scanf("%d", &item);
temp = insert (item, temp);
printf("\n\t *** Tree *** \n");
output(temp,1);
depth = 0;
depthbr(temp, &depth, 0);
printf("\nDepth = %d\n", depth);
break;
case 'D':
case 'd':
printf("Enter element :");
scanf("%d", &item);
temp = del(temp, item);
printf("\n\t *** Tree ***\n");
output(temp,1);
depth = 0;
depthbr(temp, &depth, 0);
printf("\nDepth = %d\n", depth);
break;
case 'E':
case 'e':
quit = 1;
}
}
while(!quit);
printf("\n");
}
.pa_ _
0
+___ミ 3____________________ __Š OUTPUT:
Options Choice
Insert I
Delete D
Exit E
Enter choice :I
Enter element :10
Options Choice
Insert I
Delete D
Exit E
Enter choice :I
Enter element :20
Options Choice
Insert I
Delete D
Exit E
Enter choice :D
Enter element :10
#include <stdio.h>
#include <malloc.h>
temp->item = vector[mid];
if(first>=last)
{
temp->left = NULL;
temp->right = NULL;
return(temp);
}
}
void preorder(temp)
tree *temp;
{
if(temp)
{
printf("%d", temp->item);
preorder(temp->left);
preorder(temp->right);
}
}_ _
ð_7___ミ 3____________________ __Š
void inorder(temp)
tree *temp;
{
if(temp)
{
inorder(temp->left);
printf("%d", temp->item);
inorder(temp->right);
}
}
void postorder(temp)
tree *temp;
{
if(temp)
{
postorder(temp->left);
postorder(temp->right);
printf("%",temp->item);
}
}
void triangle(temp, branch)
tree *temp;
int branch;
{
int i;
if(temp)
{
triangle(temp->right, branch+1);
printf("\n");
for(i=0;i<branch;i++)
printf(" ");
printf("%d",temp->item);
triangle(temp->left, branch+1);
}
}
void main()
{
int v1[50],i,j,temp,total,quit=0;
char c;
tree *bintree;
printf("Program for tree creation and traversal of binary
tree \n");
printf("Enter number of elements in vector :");
scanf("%d", &total);
for(i=0;i<total;i++)
{
printf("\n Enter element %d :",i);
scanf("%d", &v1[i]);
}
for(i=0;i<total;i++)
{
for(j=i+1;j<total;j++)
{
if(v1[i] > v1[j])
{
temp = v1[i];
v1[i] = v1[j];
v1[j] = temp;
}
}
}
printf("Data in ascending order\n");
for(i=0;i<total;i++)
{
printf("%5d", v1[i]);
}
printf("\n");
bintree = binarytree(v1,0,total-1);
do
{
printf("\n\t Options\t\t\tChoice");
printf("\n\t Triangular\t\t T");
printf("\n\t Diagonal\t\t D");
printf("\n\t Exit \t\t\t E");
printf("\n\t Enter choice :");
_ _
ð_7___ミ 3____________________ __Š
do
c=getchar();
while(strchr("TtDdEe",c) == NULL);
switch(c)
{
case 'T':
case 't':
printf("\n\t *** Binary Tree ***\n");
triangle(bintree,1);
case 'D':
case 'd':
printf("\n\t *** Binary Tree ***\n");
diagonal(bintree, 1);
printf("\n Preorder traversal :");
preorder(bintree);
printf("\n Inorder traversal :");
inorder(bintree);
printf("\n Postorder traversal :");
postorder(bintree);
break;
case 'E':
case 'e':
quit = 1;
}
}
while(!quit);
printf("\n");
}
_ _
ð_7___ミ 3____________________ __Š
OUTPUT:
#include <stdio.h>
main()
{
int i,j,n,v[50],yn=1;
printf("\nEnter %d elements\n",n);
for(i=0;i<n;i++)
scanf("%d", &v[i]);
for(i=0;i<n;i++)
{
if(v[i] == j)
{
printf("\nElement %d is at location %d\n",j,i+1);
yn=0;
break;
}
}
if(yn)
printf("\nElement %d not found in array\n",j);
}
.pa_ _
p_/___ミ 3____________________ __Š
OUTPUT:
Program for linear search
Enter size of the array:5
Enter 5 elements
10
20
30
40
50
Enter element to be searched :30
Original array
10 20 30 40 50
Element 30 is at location 3
.pa_ _
°"____ミ 3____________________ __Š
.pa_ _
P
-___ミ 3____________________ __Š OUTPUT:
.pa_ _
€%____ミ 3____________________ __Š
#include <stdio.h>
#include <malloc.h>
struct tree
{
int item;
struct tree *left, *right;
};
void depth(node)
struct tree *node;
{
if(node->left == NULL)
if(ele<tele)
ele=tele;
else ;
else
{
tele++;
depth(node->right);
}
tele--;
}
void preorder(node)
struct tree *node;
{
if(node != NULL)
{
printf("%i", node->item);
preorder(node->left);
preorder(node->right);
}
}
void inorder(node)
struct tree *node;
{
if(node != NULL)
{
inorder(node->left);
printf("%i", node->item);
inorder(node->right);
}
}
_ _
ð_7___ミ 3____________________ __Š
void postorder(node)
struct tree *node;
{
if(node != NULL)
{
postorder(node->left);
postorder(node->right);
printf("%i", node->item);
}
}
void disp()
{
printf("\nPreorder traversal :");
preorder(node);
printf("\nInorder traversal :");
inorder(node);
printf("\nPostorder traversal :");
postorder(node);
printf("\n");
}
void ins()
{
struct tree *temp, *prev;
int n,c,check;
do
{
printf("Enter number of elements :");
scanf("%i", &n);
fflush(stdin);
}
while(n<1);
do
{
printf("Enter elements :");
scanf("%i", &c);
fflush(stdin);
temp=node;
check=0;
if(temp == NULL)
{
node=(struct tree*)malloc(sizeof(struct tree));
temp=node;
}
else
{
while(temp!=NULL && !check)
{
prev = temp;_ _
ð_7___ミ 3____________________ __Š
if(c == temp->item)
{
printf("%i is in the tree",c);
printf("\n");
check=1;
}
else
{
if(c < temp->item)
temp=temp->left;
else
temp=temp->right;
}
}
if(!check)
{
temp = (struct tree*)malloc(sizeof(struct tree));
if(c<prev->item)
prev->left = temp;
else
prev->right = temp;
}
}
if(!check)
{
temp->item = c;
temp->left = NULL;
temp->right = NULL;
n--;
}
}
while(n > 0);
}
_ _
ð_7___ミ 3____________________ __Š
if(prs->left == NULL)
temp=prs->right;
else
temp=prs->left;
if(srs != NULL)
if(prs == srs->left)
srs->left=temp;
else
srs->right=temp;
else
node = temp;
}
void del()
{
struct tree *prs, *srs;
int n, c;
do
{
printf("Number of element (for deletion) :");
scanf("%i", &n);
fflush(stdin);
}
while(n < 1);_ _
ð_7___ミ 3____________________ __Š
do
{
printf("Enter the element :");
scanf("%i", &c);
fflush(stdin);
search(c, &srs, &prs);
if(prs == NULL)
printf("Element not found\n");
else
if(prs->left != NULL && prs->right != NULL)
delet1(prs,srs);
else
delet0(prs, srs);
n--;
}
while(n>0);
}
void main()
{
int quit=0;
char c;
node=NULL;
printf("\nProgram for operations of binary tree\n");
do
{
printf("\n\tOptions\t\t\tChoice");
printf("\n\tInsert\t\tI");
printf("\n\tDelete\t\tD");
printf("\n\tDisplay\t\tO");
printf("\n\tExit\t\tE");
printf("\n\tEnter choice :");
do
c=getchar();
while(strchr("IiDdOoEe",c) == NULL);
switch(c)
{
case 'I':
case 'i':
ins();
break;
_ _
ð_7___ミ 3____________________ __Š
case 'D':
case 'd':
del();
break;
case 'O':
case 'o':
disp();
if(node == NULL)
printf("Tree empty\n");
else
{
ele=0;
tele=0;
depth(node);
printf("Depth of tree = %i\n", ele);
}
break;
case 'E':
case 'e':
quit=1;
}
}
while(!quit);
printf("\n");
}
.pa_ _
€_ ___ミ 3____________________ __Š OUTPUT:
Options Choice
Insert I
Delete D
Display O
Exit E
Enter choice :O
_
_ 8_8_ _
__/*Dsp-26 Write a program in C to implement the Binary search
_
_ d_d_ _
__by recursion*/
#include <stdio.h>
void main()
{
int v1[50],i,j,number,pos,search,temp,mid;
void binary_search();
printf("\nBinary search by recursion\n");
printf("Enter number of elements of array (1 to 50):");
scanf("%d", &number);
printf("Enter %d element\n",number);
for(i=0;i<number;i++)
scanf("%d", &v1[i]);
printf("\n");
for(i=0;i<number-1;i++)
for(j=i+1;j<number;j++)
if(v1[i] >v1[j])
{
temp = v1[i];
v1[i] = v1[j];
v1[j] = temp;
}
printf("Enter element to be searched :");
scanf("%d", &search);
pos=0;
i=1;
binary_search(v1,i,number,pos,search);
}
void binary_search(v1,min,max,pos,search)
int v1[50],min,max,pos,search;
{
int mid;
if(min >max)
pos = 0;
_ _
ð_7___ミ 3____________________ __Š
else
{
mid = (min + max)/2;
if(search<v1[mid])
{
max = mid - 1;
binary_search(v1,min,max,pos,search);
}
else
if(search>v1[mid])
{
min = mid + 1;
binary_search(v1,min,max,pos,search);
}
else
pos=mid;
if(pos>0)
printf("Your element %d is at position no %d\n",
search,pos+1);
}
}
.pa_ _
`_-___ミ 3____________________ __Š
OUTPUT:
#include<stdio.h>
main()
{
int i, j, n, v[50], temp, last, yn=1;
printf("Program for bubble sort\n\n");
printf("Enter size of the array :");
scanf("%d", &n);
printf("\nEnter %d elements\n",n);
for(i=0; i<n; i++)
scanf("%d", &v[i]);
printf("\n\t original array \n");
for(i=0;i<n;i++)
printf("5d", v[i]);
printf("\n");
last=n-1;
for(i=0;i<n-1;i++)
{
for (j=0;j<last-i;j++)
{
if(v[j]>v[j+1])
{
temp = v[j];
v[j]=v[j+1];
v[j+1]=temp;
yn=0;
}
}
}
if(!yn)
yn=1;
3 5 10 20 30
.pa_ _
p&____ミ 3____________________ __Š
/*Write a program in C to give the transpose of a sparse matrix*/
#include <stdio.h>
int m,n,count=0;
main()
{
int a[10][10], i, j, b[10][10], c[10][10];
clrscr();
printf("Enter m and n\n");
scanf("%d %d", &m, &n);
printf("Enter the matrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
if(a[i][j] != 0)
count++;
}
if(count<m*n-count)
printf("The matrix entred is a sparse matrix\n");
else
{
printf("The matrix is not sparse\n");
exit(1);
}
sparse(a,b);
print(b,count+1,3);
transpose(b,c);
printf("the transpose of matrix is \n");
print(c,3,count+1);
printf("\n\n\n");
getch();
}
sort_vect(v2,m-1);
i=j=k=0;
Enter 4 element
10 20 30 40
Enter size of the vector 2:3
Enter 4 element
1 2 5 22
Sorted Vector 1
10 20 30 40
Sorted Vector 2
1 2 5
.PA_ _
_-____ミ 3____________________ __Š
_
_ Â_Â_ _
__/*Dsp32-Write a program in C to implement the Heap sort algorithm*/
#include <stdio.h>
main()
{
int v[50],i,n;
void crheap();
void sort();
printf("\nEnter %d elements\n",n);
for(i=1;i<=n;++i)
scanf("%d", &v[i]);
sort(v,n);
void crheap(v,n)
int v[50],n;
{
int i,j,key,q;
for(q=2;q<=n;++q)
{
i=q;
key=v[q];
j=(int)(i/2);
if((j+1)<q)
if(v[j+1]>v[j])
j=j+1;
while((j<(q-1)) && (v[j] > key))
{
v[i] = v[j];
i=j;
j=2*i;
if((j+1)<q)
if(v[j+1]>v[j])
j=j+1;
else
if(j>n)
j=n;
}
v[i] = key;
}
return;
}
.pa_ _
°_#___ミ 3____________________ __Š OUTPUT:
Program for heap sort
Enter size of the array :5
Enter 5 elements
10 30 3 4 2
*** Sorted array ***
2 3 4 10 30
.pa_ _
_, ___ミ 3____________________ __Š
/*Dsp4-Write a program in C for implementation ofPolynomial addition*/
#include <stdio.h>
struct list
{
int coef, exp;
/* COFFICIENT AND EXPONENT OF POLYNOMIAL FUNCTION*/
struct list *next;
}*first, *second, *new, *ptr, *prev, *p, *sum, *pt;
main()
{
clrscr();
first=second=new=ptr=prev=p=sum=pt=NULL;
printf("\n Enter the values of first function:");
polyfirst();
printf("\n Enter the values of second function:");
polysecond();
printf("The Sum of first & second poly function:");
polysum();
}
polyfirst()
{
char ch='y';
while(toupper(ch) == 'Y')
{
new=(struct list *)malloc(sizeof(struct list));
printf("\n Enter the Coeff & Expo of variables of
first function");
scanf("%d%d", &new->coef, &new->exp);
new->next=NULL;
if(first == NULL)
{
first=new;
ptr=new;
}
else
{
ptr->next=new;
ptr=new;
}
printf("\n Do U want to add a variables in first
functino ");
fflush(stdin);
ch=getchar();
}
}
_ _
ð_7___ミ 3____________________ __Š
polysecond()
{
char ch ='y';
while(toupper(ch) == 'Y')
{
new=(struct list *)malloc(sizeof(struct list));
printf("\n Enter The Coeff & Expo of Variables of
second function");
scanf("%d %d", &new->coef, &new->exp);
new->next= NULL;
if(second == NULL)
{
second = new;
prev=new;
}
else
{
prev->next=new;
prev=new;
}
printf("\n Do U want to continue add variables in
second function");
fflush(stdin);
ch=getchar();
}
}
polysum()
{
new=(struct list *) malloc(sizeof(struct list));
for(ptr=first, prev=second;(ptr!=NULL) && (prev!=NULL);)
{
if(ptr->exp == prev->exp)
{
new->exp=ptr->exp;
new->coef=ptr->coef+prev->coef;
ptr=ptr->next;
goto a;
}
if(ptr->exp > prev->exp)
{
new->exp=ptr->exp;
new->coef=ptr->coef;
ptr=ptr->next;
goto a;
}
if(ptr->exp < prev->exp)
{
new->exp=prev->exp;
new->coef=prev->coef;
ptr=ptr->next;
goto a;
}
a:;
_ _
ð_7___ミ 3____________________ __Š
new->next = NULL;
if(sum==NULL)
{
sum=new;
pt=new;
}
else
if(sum!=NULL)
{
pt->next=new;
pt=new;
}
new=(struct list *)malloc(sizeof(struct list));
}
if((ptr==NULL) && (prev != NULL))
{
new->exp=prev->exp;
new->coef=prev->coef;
prev=prev->next;
goto a;
}
.pa_ _
ð_'___ミ 3____________________ __Š OUTPUT:
.PA_ _
°"____ミ 3____________________ __Š
/*Write a program in C for searching an element of a linked list*/
#include <stdio.h>
#define NULL 0
struct list_element
{
int item;
struct list_element *next;
};
typedef struct list_element node;
main()
{
node *start;
int key,choice;
node *create();
void display();
node *lookup();
node *locate(node*,int);
_ _
ð_7___ミ 3____________________ __Š
void display (first)
node *first;
{
printf("\nRoot ->");
while(first!= NULL)
{
printf("%d->",first->item);
first=first->next;
}
printf("NULL\n\n");
}
node *lookup(first)
node *first;
{
node *locate();
node *tag, *temp;
int target,newitem, opt;
tag = first;
printf("Element to be searched ? ");
scanf("%d", &target);
OUTPUT:
Root ->10->20->NULL
Element to be searched ? 20
Element at position 2
.PA_ _
Ð ____ミ 3____________________ __Š
_
_ š
š
_
__/* program sorts a given linked list */
#define NULL 0
struct element_list
{
int info;
struct element_list *next;
};
typedef struct element_list node;
main()
{
node *start, *list, *pass;
int key, choice,temp;
node *create();
void display();
for(list;list->next != NULL;list=list->next)
{
for(pass=list->next; pass !=NULL; pass=pass->next)
if(list->info > pass->info)
{
temp = list->info;
list->info = pass->info;
pass->info = temp;
}
}
node *create(first)
node *first;
{
node *temp, *prev;
int element;
prev = first = NULL;
printf("\n Enter the integer (-9999 to exit) :");
scanf("%d", &element);
_ _
ð_7___ミ 3____________________ __Š
while(element != -9999)
{
temp = (node*)malloc(sizeof(node));
temp->info = element;
temp->next = NULL;
if(first == NULL)
first = temp;
else
prev->next = temp;
void display(first)
node *first;
{
printf("\nRoot->");
while(first != NULL)
{
printf("%d->", first->info);
first = first->next;
}
printf("NULL\n\n");
}
.pa_ _
à_&___ミ 3____________________ __Š OUTPUT:
Root->10->20->5->2->NULL
Root->2->5->10->20->NULL
.PA_ _
_-____ミ 3____________________ __Š
_
_ *_*_ _
__/*Dsp8-Write a program in C that reverses a given linked list*/
#include<stdio.h>
#include<malloc.h>
#define NULL 0
struct element_list
{
int info;
struct element_list *next;
};
typedef struct element_list node;
main()
{
node *first, *prev, *current, *save;
int key, choice;
node *create();
void display();
printf("Program for reversing of linked list\n");
first=create(first);
printf("\n\t *** Linked list ***\n");
display (first);
printf("\n");
current = first;
prev = NULL;
while(current != NULL)
{
save = current->next;
current->next = prev;
prev = current;
current = save;
}
first = prev;
printf("\n\t *** Reversed Linked list ***\n");
display(first);
printf("\n");
}
node *create(record)
node *record;
{
node *temp, *prev;
int element;
prev = NULL;
record = NULL;
printf("\n Enter the integer (-9999 to exit) :");
scanf("%d", &element);
_ _
ð_7___ミ 3____________________ __Š
while(element != -9999)
{
temp = (node*)malloc(sizeof(node));
temp->info = element;
temp->next = NULL;
if(prev == NULL)
record = temp;
else
prev->next = temp;
prev=temp;
printf("\n Enter the integer (-9999 to exit) :");
scanf("%d", &element);
}
return (record);
}
void display(record)
node *record;
{
printf("\nRoot->");
while(record != NULL)
{
printf("%d->", record->info);
record = record->next;
}
printf("NULL\n\n");
return;
}
.pa_ _
ð_'___ミ 3____________________ __Š
OUTPUT:
Root->10->20->30->NULL
Root->30->20->10->NULL
.PA_ _
Ð ____ミ 3____________________ __Š
_
_ 8_8_ _
__/*DSlab-9 Write a program in C to concatenate the two given
_
_ x_x_ _
__linked lists into one list*/
#include <stdio.h>
#include <malloc.h>
#define NULL 0
struct element_list
{
int item;
struct element_list *next;
};
typedef struct element_list node;
main()
{
node *start, *one, *two, *three;
int key, choice;
void create();
void display();
void concat();
printf("Program ot concatenate two list\n");
printf("First list\n");
one = (node *)malloc(sizeof(node));
create(one);
printf("Second list\n");
two = (node *)malloc(sizeof(node));
create(two);
printf("\n\t *** Linked list 1 ***\n");
display(one);
printf("\n\t *** Linked list 2 ***\n");
display(two);
three = (node *)malloc(sizeof(node));
concat(one,two,three);
printf("\n\t *** Concatented list ***");
display(three);
printf("\n");
}
void create(record)
node *record;
{
printf("Enter the integer (-9999 to exit) :");
scanf("%d", &record->item);
if(record->item == -9999)
record->next = NULL;
else
{
record->next = (node *)malloc(sizeof(node));
create(record->next);
}
return;
}_ _
ð_7___ミ 3____________________ __Š
void display(record)
node *record;
{
if(record->next!= NULL)
{
printf("%d->", record->item);
display(record->next);
}
return;
}
void concat(one, two, three)
node *one, *two, *three;
{
while(one->next!=NULL)
{
three->item = one->item;
one = one->next;
three->next=(node*)malloc(sizeof(node));
three=three->next;
}
while(two->next!= NULL)
{
three->item = two->item;
two= two->next;
three->next = (node *)malloc(sizeof(node));
three = three->next;
}
three->next = NULL;
return;
}
.pa_ _
ミ_!___ミ 3____________________ __Š OUTPUT:
#include<stdio.h>
main()
{
int i, j, k, n, A[50][50],p[50][50],temp,last,yn=1;
printf("Program for transitive closure\n\n");
printf("Enter size of the graph :");
scanf("%d",&n);
printf("\nEnter %d elements\n",n);
for (i=0;i<n;i++)
for (j=0;j<n;j++)
scanf("%d",&A[i][j]);
printf("\n\t The adjecency matrix is \n");
for ( i=0; i<n; i++)
for (j=0; j<n; j++)
printf("5d", A[i][j]);
printf("\n");
for (i=0; i<n; i++)
for (j=0; j<n; j++)
p[i][j] = A[i][j];
for (k=0; k<n; k++)
for (i=0; i<n; i++)
for (j=0; j<n;j++)
p[i,j]==p[i,k]&&p[k,j];
printf("\n\t The transitive closure is\n");
for(k=0;k<n;j++);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
printf("%5d", A[i][j]);
printf("\n");
}
.pa_ _
Ð_%___ミ 3____________________ __Š OUTPUT:
.PA_ _
ミ$____ミ 3____________________ __Š
_
_ ’_’_ _
__/* Dslab-20 Write a Program in C to concatenate the given
_
_ ¾_¾_ _
__two strings*/
#include<stdio.h>
main()
{
char s1[20], s2[20], s3[40];
int i,j,k;
printf("Enter the first string ==");
scanf("%s", s1);
printf("\nEnter the second string ==");
scanf("%s", s2);
i = strlen(s1);
j = strlen(s2);
for (k=0; k<i; k++)
s3[k] = s1[k];
for (k=0; k<j; k++)
s3[i+k] = s2[k];
s3[i+j] = '\0';
printf("\n\n Two strings are %s and %s \n new string is %s \n",
s1,s2,s3);
}
.pa_ _
P_____ミ 3____________________ __Š OUTPUT:
.PA_ _
+
___ミ 3____________________ __Š
_
_ ’_’_ _
__/* Dsp33-Write a program in C for the creation of a tree*/
#include <stdio.h>
#include <malloc.h>
{
if(!s)
{
s=(tree*)malloc(sizeof(tree));
s->item=item;
s->left=NULL;
s->right=NULL;
return(s);
}
if(item < s->item)
s->left = insert(item, s->left);
else
if(item > s->item)
s->right = insert(item, s->right);
return(s);
}
if(ped)
{
display(ped->right, level+1);
printf("\n");
for(i=0;i<level;i++)
printf(" ");
printf("%d",ped->item);
display(ped->left, level+1);
}
}
_ _
ð_7___ミ 3____________________ __Š
void main()
{
int item;
tree *ped = NULL;
printf("Program for tree creation\n");
while(1)
{
printf("\n Enter item (-9999 to exit) :");
scanf("%d", &item);
if(item == -9999)
break;
ped = insert(item, ped);
printf("\n\t *** Tree ***\n");
display(ped,1);
}
}
.pa_ _
ð-____ミ 3____________________ __Š OUTPUT:
10
Enter item (-9999 to exit) :20
20
10
Enter item (-9999 to exit) :30
.PA_ _
_-____ミ 3____________________ __Š
_
_
_
_ _
__/* Heap Sort */
#include<stdio.h>
#include <conio.h>
crheap(int k[20],int n)
{
int i,j,key,q;
for (q=2; q<=n; q++)
{
i=q;
key=k[q];
j=(int)(i/2);
while ( (i>1) && (key > k[j]) )
{
k[i]=k[j];
i=j;
j=(int)(i/2);
if (j < 1)
j=1;
}
k[i]=key;
}
}
heapsort(int k[20],int n)
{
int q,temp,i,j,key;
crheap(k,n);
for (q=n; q>=2; q--)
{
temp=k[1];
k[1]=k[q];
k[q]=temp;
i=1;
key=k[1];
j=2;
if ( (j+1) <q )
if ( k[j+1] > k[j])
j++;
while( (j<=(q-1) ) && (k[j] > key) )
{
k[i]=k[j];
i=j;
j=2*i;
if ( (j+1) < q)
if (k[j+1] > k[j])
j++;
else
if (j > n)
j=n;
k[i]=key;
}
}
}
_ _
ð_7___ミ 3____________________ __Š
main()
{
int k[20],i1,n;
printf("Enter the size of the vector to be sorted: ");
scanf("%d",&n);
printf("Input the given number: ");
for (i1=1; i1<=n; i1++)
scanf("%d",&k[i1]);
printf("\n");
heapsort(k,n);
printf("The srted vector is: \n");
for (i1=1; i1<=n; i1++)
printf("%4d",k[i1]);
getch();
}
OUTPUT:
.PA_ _
_"___ミ 3____________________ __Š
_
_ H_H_ _
__/* Circular Queue */
#include<stdio.h>
struct cirqueue
{
int data;
struct cirqueue *link;
}*front=NULL,*rear=NULL,*temp;
void insert(int );
void display();
int isempty();
int delete();
int size();
void main()
{
int opt,n;
do
{
clrscr();
printf("\n\t\t##CIRCULAR QUEUE OPERATIONS##\n");
printf("\n\t\t1:INSERTION\n");
printf("\t\t2:DELETTION\n");
printf("\t\t3:ISEMPTY\n");
printf("\t\t4:DISPLAY\n");
printf("\t\t5:SIZE\n");
printf("\t\t6:EXIT\n");
printf("\n\t\tEnter your option:");
scanf("%d",&opt);
printf("\n\t\t");
switch(opt)
{
case 1:
printf("Enter element to insert:");
scanf("%d",&n);
insert(n);
break;
case 2:
if(!isempty())
printf("Deleted element is:%d",delete());
else
printf("Queue is empty");
break;
case 3:
if(isempty())
printf("Queue is empty");
else
printf("Queue is not empty");
break;
_ _
ð_7___ミ 3____________________ __Š
case 4:
if(!isempty())
display();
else
printf("Queue is empty");
break;
case 5:
printf("Size of the queue is:%d",size());
break;
case 6: exit(1);
otherwise:
printf("Invalid option");
}
getch();
}while(opt<7);
}
void insert(int m)
{
temp=(struct cirqueue*)malloc(sizeof(struct cirqueue));
temp->data=m;
temp->link=NULL;
if(front==NULL)
{
front=temp;
rear=temp;
}
else
{
rear->link=temp;
rear=temp;
}
rear->link=front;
return;
}
int delete()
{
int m;
temp=front;
if(front==rear)
front=rear=NULL;
else
{
front=front->link;
rear->link=front;
}
m=temp->data;
free(temp);
return(m);
}_ _
ð_7___ミ 3____________________ __Š
int isempty()
{
if(front==NULL)
return(1);
else
return(0);
}
void display()
{
int m;
temp=front;
printf("\n\t\tFront");
do
{
printf("<-%d",temp->data);
temp=temp->link;
}while(temp!=front);
printf("<-Rear");
return;
}
int size()
{
int m=0;
temp=front;
do
{
temp=temp->link;
m++;
}while(temp!=front);
return(m);
}
.pa_ _
À_$___ミ 3____________________ __Š
OUTPUT:
1:INSERTION
2:DELETTION
3:ISEMPTY
4:DISPLAY
5:SIZE
6:EXIT
1:INSERTION
2:DELETTION
3:ISEMPTY
4:DISPLAY
5:SIZE
6:EXIT
1:INSERTION
2:DELETTION
3:ISEMPTY
4:DISPLAY
5:SIZE
6:EXIT
Front<-10<-20<-Rear
.pa_ _
€_0___ミ 3____________________ __Š
#define MAX_SIZE 50
#define TRUE 1
#define FALSE 0
#include<stdio.h>
main()
{
int i,j,n,v[50], yn=1, first, mid, last;
int p,f,size;
printf("Program for hash searching\n\n");
printf("Enter size of the array :");
scanf("%d", &n);
printf("\n Enter %d elements of the array\n",n);
for(i=0;i<n;i++)
scanf("%d", &v[i]);
_ _
ð_7___ミ 3____________________ __Š
if(table[start]==key)
{
active=FALSE;
found=TRUE;
temp=table[start];
}
else
{
temp=table[start];
table[start]=key;
}
while(active){
position=(position+1)%tablesize;
if (table[position]==key)
{
active=FALSE;
if(position!=start)found=TRUE;
}
else
if(table[position]==empty)active=FALSE;
}
table[start]=temp;
}
.pa_ _
€_ ___ミ 3____________________ __Š
OUTPUT:
Original array
10 20 30 40 50