Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void Display(int b[],int k);
- void Edit_Array(int b[],int nn, int pp, int vv);
- int Insertion_lastposition(int b[],int nn,int vv);
- int Insertion_Specificposition(int b[],int nn,int pp,int vv);
- void Linear_search(int b[],int nn,int vv);
- int Deletion(int b[],int nn,int pp);
- void Bubble_sort(int b[],int nn);
- void Binary_search(int b[], int nn,int vv);
- int main()
- {
- int n,a[100],i,c,b=1,p,v;
- printf("\n How Many Values:\n");
- scanf("%d",&n);
- printf("\n Enter Values:\n");
- for(i=1;i<=n;i++)
- scanf("%d",&a[i]);
- while(b)
- {
- printf("\n---Menu---\n");
- printf("press 0 for Quiet\n");
- printf("press 1 for Display\n");
- printf("press 2 for insertion at last position\n");
- printf("press 3 for insertion at specific position\n");
- printf("press 4 for Deleting from specific position\n");
- printf("press 5 for Linear Search\n");
- printf("press 6 for Bouble Sort\n");
- printf("press 7 for Binary Search\n");
- printf("press 8 for Edit\n");
- printf("\n Enter Your Choice\n");
- scanf("%d",&c);
- switch(c)
- {
- case 0: b=0;
- break;
- case 1: printf("\n choice=Display\n");
- if (n!=0)
- Display(a,n);
- else
- printf("The Array is Empty\n");
- break;
- case 2: printf ("\n Choice=insertion at last position\n");
- printf ("Enter new Value\n");
- scanf("%d",&v);
- n=Insertion_lastposition(a,n,v);
- break;
- case 3: printf ("\n choice=Insertion at specific position\n");
- if(n>0)
- {
- K: printf ("\n Enter position Between %d to %d :",1,n+1);
- scanf("%d",&p);
- if(p>=1 && p<=n+1)
- {
- printf("\n Enter New value\n");
- scanf("%d",&v);
- n=Insertion_Specificposition(a,n,p,v);
- }
- else
- {
- printf("\n Wrong position\n");
- goto K;
- }
- }
- else
- printf("\n Array is Empty\n");
- break;
- case 4: printf("\n choice=Deletion\n");
- if (n!=0)
- {
- X: printf("\n Enter position Between %d to %d\n",1,n);
- scanf("%d",&p);
- if (p>=1 && p<=n)
- n= Deletion(a,n,p);
- else
- {
- printf ("\n Wrong Position\n");
- goto X;
- }
- }
- else printf ("\n No Data to Delete\n");
- break;
- case 5: printf("\n choice=Linear Search\n");
- if(n!=0)
- {
- printf("\n Enter Value for Searching\n");
- scanf("%d",&v);
- Linear_search(a,n,v);
- }
- else
- printf("\n No Data for Linear Searching\n");
- break;
- case 6: if (n!=0)
- {
- Bubble_sort(a,n);
- printf("\n Sorted Successfully \n");
- }
- else printf ("\n No Data To Sort\n");
- break;
- case 7: printf("\n choice=Binary Search\n");
- if(n!=0)
- {
- printf("\n Enter Vlaue for Searching\n");
- scanf ("%d",&v);
- Binary_search(a,n,v);
- }
- else
- printf("\n The Array is Empty\n");
- break;
- case 8: printf("\n choice= Edit\n");
- if(n>0)
- {
- M: printf("Enter position Between %d to %d\n",1,n);
- scanf("%d",&p);
- if(p>=1 & p<=n)
- {
- printf("Enter Value\n");
- scanf("%d",&v);
- Edit_Array(a,n,p,v);
- }
- else
- {
- printf("\n Wrong Position\n");
- goto M;
- }
- }
- else
- printf("\n No Data to Edit\n");
- break;
- default:printf("\n Wrong Choice\n");
- break;
- }
- }
- }
- void Display(int b[],int k)
- {
- int j;
- printf("\n The values Are\n");
- for (j=1;j<=k;j++)
- printf ("%d\n",b[j]);
- }
- int Insertion_lastposition(int b[],int nn,int vv)
- {
- b[nn+1]=vv;
- printf("\n Inserted Successfully\n");
- return nn+1;
- }
- int Insertion_Specificposition(int b[],int nn,int pp,int vv)
- {
- int j;
- for (j=nn; j>=pp;j--)
- b[j+1]=b[j];
- b[pp]=vv;
- printf("\n Inserted At potion %d",pp);
- return nn+1;
- }
- int Deletion(int b[],int nn,int pp)
- {
- int j,z;
- z=b[pp];
- for (j=pp;j<nn;j++)
- b[j]=b[j+1];
- printf("\n The Deleted Value %d from position %d\n\n",z,pp);
- return nn-1;
- }
- void Bubble_sort(int b[], int nn)
- {
- int i,j,t;
- for (i=1;i<=nn;i++)
- {
- for(j=1;j<=nn-1;j++)
- {
- if (b[j]> b[j+1])
- {
- t=b[j];
- b[j]=b[j+1];
- b[j+1]=t;
- }
- }
- }
- }
- void Edit_Array(int b[], int nn,int pp,int vv)
- {
- b[pp]=vv;
- }
- void Binary_search(int b[],int nn, int vv)
- {
- int beg,end,mid;
- Bubble_sort(b,nn);
- beg=1;
- end=nn;
- do
- {
- mid=(beg+end)/2;
- if(vv<b[mid])
- end=mid-1;
- else if (vv>b[mid])
- beg=mid+1;
- }
- while(vv!=b[mid] && beg<=end);
- if(vv==b[mid])
- printf("\n Found \n");
- else
- printf ("\n Not Found\n");
- }
- void Linear_search(int b[],int nn,int vv)
- {
- int j,x=0;
- for(j=1;j<=nn;j++)
- {
- if(b[j]==vv)
- {
- printf("\n Found At Position %d",j);
- x++;
- }
- }
- if(x!=0)
- {
- printf("\n Found %d Times\n",x);
- }
- else
- printf("\n Not Found\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement