Programs
Programs
#include<stdio.h>
#include<conio.h>
#define MAX_SIZE 5
void binary_search(int[],int);
int main() {
int arr_search[MAX_SIZE], i,element;
binary_search(arr_search,element);
getch();
}
while (f <= r) {
mid = (f+r)/2;
if (fn_arr[mid] == element) {
printf("\nSearch Element : %d : Found : Position : %d.\n", element,
mid+1);
break;
}
else if (fn_arr[mid] < element)
f = mid + 1;
else
r = mid - 1;
}
if (f > r)
printf("\nSearch Element : %d : Not Found \n", element);
}
Sample Output
Simple Binary Search Example - Array and Functions
#include<stdio.h>
#include<conio.h>
#define MAX_SIZE 5
int main() {
int arr_search[MAX_SIZE], i, element;
getch();
}
if (i == MAX_SIZE)
printf("\nSearch Element : %d : Not Found \n", element);
}
Sample Output:
Output 1:
Output 2:
Void Insert()
{
Int X;
If(Rear==Max-1)
Printf("Queue Is Overflow\N");
Else
{
Printf("Enter Element To Be Insert:");
Scanf("%D",&X);
Q[++Rear]=X;
}
}
Void Delet()
{
Int A;
If((Front==0)&&(Rear==-1))
{
Printf("Queue Is Underflow\N");
Getch();
Exit();
}
A=Q[Front++];
Printf("Deleted Element Is:%D\N",A);
If(Front>Rear)
{
Front=0;
Rear=-1;
}
}
Void Display()
{
Int I;
If(Front==0&&Rear==-1)
{
Printf("Queue Is Underflow\N");
Getch();
Exit();
}
For(I=Front;I<=Rear;I++)
Printf("\T%D",Q[I]);
Printf("\N");
}
Getch();
struct Node
{
int e;
Position previous;
Position next;
};
int isLast(Position p)
{
return (p->next == NULL);
}
void Display(List l)
{
printf("The list element are :: ");
Position p = l->next;
while(p != NULL)
{
printf("%d -> ", p->e);
p = p->next;
}
}
void main()
{
int x, pos, ch, i;
List l, l1;
l = (struct Node *) malloc(sizeof(struct Node));
l->previous = NULL;
l->next = NULL;
List p = l;
printf("DOUBLY LINKED LIST IMPLEMENTATION OF LIST ADT\n\n");
do
{
printf("\n\n1. INSERT\t 2. DELETE\t 3. FIND\t 4. PRINT\t 5. QUIT\n\nEnter the choi
scanf("%d", &ch);
switch(ch)
{
case 1:
p = l;
printf("Enter the element to be inserted :: ");
scanf("%d",&x);
printf("Enter the position of the element :: ");
scanf("%d",&pos);
for(i = 1; i < pos; i++)
{
p = p->next;
}
Insert(x,l,p);
break;
case 2:
p = l;
printf("Enter the element to be deleted :: ");
scanf("%d",&x);
Delete(x,p);
break;
case 3:
p = l;
printf("Enter the element to be searched :: ");
scanf("%d",&x);
p = Find(x,p);
if(p == NULL)
printf("Element does not exist!!!\n");
else
printf("Element exist!!!\n");
break;
case 4:
Display(l);
break;
}
}
while(ch<5);
}
OUTPUT:
DOUBLY LINKED LIST IMPLEMENTATION OF LIST ADT
struct Node
{
int e;
Position next;
};
void Display(List l)
{
printf("The list element are :: ");
Position p = l->next;
while(p != l)
{
printf("%d -> ", p->e);
p = p->next;
}
}
void main()
{
int x, pos, ch, i;
List l, l1;
l = (struct Node *) malloc(sizeof(struct Node));
l->next = l;
List p = l;
printf("CIRCULAR LINKED LIST IMPLEMENTATION OF LIST ADT\n\n");
do
{
printf("\n\n1. INSERT\t 2. DELETE\t 3. FIND\t 4. PRINT\t 5. QUIT\n\nEnter the choi
scanf("%d", &ch);
switch(ch)
{
case 1:
p = l;
printf("Enter the element to be inserted :: ");
scanf("%d",&x);
printf("Enter the position of the element :: ");
scanf("%d",&pos);
for(i = 1; i < pos; i++)
{
p = p->next;
}
Insert(x,l,p);
break;
case 2:
p = l;
printf("Enter the element to be deleted :: ");
scanf("%d",&x);
Delete(x,p);
break;
case 3:
p = l;
printf("Enter the element to be searched :: ");
scanf("%d",&x);
p = Find(x,p);
if(p == l)
printf("Element does not exist!!!\n");
else
printf("Element exist!!!\n");
break;
case 4:
Display(l);
break;
}
}while(ch<5);
return 0;
}
OUTPUT:
CIRCULAR LINKED LIST IMPLEMENTATION OF LIST ADT
main()
{
int list[MAX], num;
//clrscr();
printf("\n***** Enter the number of elements Maximum [10] *****\n");
scanf("%d",&num);
read_data(list,num);
printf("\n\nElements in the list before sorting are:\n");
print_data(list,num);
quicksort(list,0,num-1);
printf("\n\nElements in the list after sorting are:\n");
print_data(list,num);
//getch();
}
OUTPUT:
#define MAX_SIZE 5
int arr_sort[MAX_SIZE];
int main() {
int i;
while (j <= d)
t[k++] = arr_sort[j++];
Sample Output:
Simple Merge Sort Example - Functions and Array
Enter 5 Elements for Sorting
67
57
45
32
13
Your Data : 67 57 45 32 13
Sorted Data : 13 32 45 57 67