To merge two sorted arrays into one sorted
To merge two sorted arrays into one sorted
#include<stdio.h>
#include<conio.h>
b[p3++] = a[p1++];
else
b[p3++] = a[p2++];
}
while (p1 < mid)
{
b[p3++] = a[p1++];
}
while (p2 <= ub)
{
b[p3++] = a[p2++];
}
for (k = lb; k < p3; k++)
{
a[k] = b[k];
}
}
}
}
while(choice!=4);
return 0;
}
void push()
{
if(top>=n-1)
{
printf("\n\tSTACK is over flow");
}
else
{
printf(" Enter a value to be pushed:");
scanf("%d",&x);
top++;
stack[top]=x;
}
}
void pop()
{
if(top<=-1)
{
printf("\n\t Stack is under flow");
}
else
{
printf("\n\t The popped elements is
%d",stack[top]);
top--;
}
}
void display()
{
if(top>=0)
{
printf("\n The elements in STACK \n");
for(i=top; i>=0; i--)
printf("\n%d",stack[i]);
printf("\n Press Next Choice");
}
else
{
printf("\n The STACK is empty");
}
int main()
{
int n, a[5], i, b, key, low, high, mid;
printf("Which case you want: ");
scanf("%d", &n);
switch (n)
{
case 1:
printf("Linear Search\n");
printf("Enter the values:\n");
for (i = 0; i < 10; i++)
{
scanf("%d", &a[i]);
}
printf("Which value you want to search: ");
scanf("%d", &b);
for (i = 0; i < 10; i++)
{
if (a[i] == b)
{
break;
}
}
if (i < 10)
{
printf("Search is found at %d location",i);
}
else
{
printf("Search is not found");
}
break;
case 2:
printf("Binary Search\n");
printf("Enter the value of number: ");
scanf("%d", &n);
printf("Enter %d integers n:\n", n);
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
printf("Enter the value to find: \n");
scanf("%d", &key);
low = 0;
high = n - 1;
mid = (low + high) / 2;
while (low <= high)
{
if (a[mid] < key)
low = mid + 1;
else if (a[mid] == key)
{
printf("\nThe number, %d found at Position
%d", key, mid + 1);
break;
}
else
high = mid - 1;
return 0;
}