Program To Insert Element in Array
Program To Insert Element in Array
int i;
for (i = n - 1; (i >= 0 && arr[i] > key); i--)
arr[i + 1] = arr[i];
arr[i + 1] = key;
return (n + 1);
}
// Inserting key
n = insertSorted(arr, n, key, capacity);
return 0;
}
delete int main()
{
int array[100], position, c, n;
printf("Enter %d elements\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
if (position >= n+1)
printf("Deletion not possible.\n");
else
{
for (c = position - 1; c < n - 1; c++)
array[c] = array[c+1];
printf("Resultant array:\n");
for (c = 0; c < n - 1; c++)
printf("%d\n", array[c]);
}
return 0;
}
scanf("%d", &n);
scanf("%d", &array[c]);
scanf("%d", &value);
if(array[c]==value)
array[j]=array[j+1];
}
printf("Resultant array:\n");
printf("%d\n", array[c]);
return 0;
Search
for (c = 0; c < n; c++)
{
if (array[c] == search) /* If required element is found */
{
printf("%d is present at location %d.\n", search, c+1);
break;
}
}
if (c == n)
printf("%d isn't present in the array.\n", search);
union
#include<stdio.h>
/* Function prints union of arr1[] and arr2[]
m is the number of elements in arr1[]
n is the number of elements in arr2[] */
int printUnion(int arr1[], int arr2[], int m, int n)
{
int i = 0, j = 0;
while (i < m && j < n)
{
if (arr1[i] < arr2[j])
printf(" %d ", arr1[i++]);
else if (arr2[j] < arr1[i])
printf(" %d ", arr2[j++]);
else
{
printf(" %d ", arr2[j++]);
i++;
}
}
union
#include<stdio.h>
printf("\n identical");
return 0;
stack
/
********************************************
**********
QUEUE C++
AUTHOR
URI:https://mostafa.itnishi.com
********************************************
**********/
#include<iostream>
#include<conio.h>
using namespace std;
int top=-1, z[5];
void push(int value)
{
if(top==4)
{
cout<<"\n Stack is Full or
overflow!\n";
}
else
{
top++;
z[top]=value;
}
}
void pop()
{
if(top==-1)
{
cout<<"n stack is Empty or
underflow!\n";
}
else
{
top--;
}
}
void display()
{
if(top==-1)
{
cout<<"\n nothing to display !\n";
}
else
{
cout<< "\n array is : \n";
for(int i=0;i<=top;i++)
{
cout<<"\t"<<z[i];
}
}
}
int main()
{
int value, choice;
do{
cout<<"\n 1.push \n 2.pop \n
3.display \n 4.exit\n \n input choice: ";
cin>>choice;
if(choice==1)
{
cout<<"\n enter a value";
cin>> value;
push(value);
}
if(choice==2)
{
pop();
}
if(choice==3)
{
display();
}
}
while(choice!=4);
cout<<"\n\n\n Existing......\n";
getch();
return 0;
}