Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void display_Array(int b[],int k);
- void edit (int b[],int pp, int vv);
- int Insertion_lastpositon (int b[],int nn, int vv);
- int Insertion_specification (int b[],int nn, int vv,int pp);
- int Deletion (int b[], int nn, int pp);
- void linear_search(int b[],int nn, int vv);
- void Bubble_short (int b[], int nn);
- void Binary_search (int b[],int nn,int vv);
- int main ()
- {
- int a[100],n,i,c,b=1,v,p;
- printf("\n Enter 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("\n pres 0 for Quit\n");
- printf("\n pres 1 for display\n");
- printf("\n pres 2 for insertion at last position\n");
- printf("\n pres 3 for insertion at specific position\n");
- printf("\n pres 4 for delete from specific position\n");
- printf("\n pres 5 for linear search\n");
- printf("\n pres 6 for Bubble sort\n");
- printf("\n pres 7 for Binary search\n");
- printf("\n pres 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_Array(a,n);
- else
- printf("\n No data to display\n");
- break;
- default:printf("\n Wrong choice\n");
- break;
- case 2: printf ("\n choice = Insertion at last position \n");
- printf("Enter new value \n");
- scanf ("%d",&v);
- n=Insertion_lastpositon(a,n,v);
- break;
- case 3: printf("\n choice = insertion att specification\n");
- if(n!=0)
- {
- K:printf("\n Enter position between %d to %d \n \n",1,n+1);
- scanf("%d",&p);
- if(p>=1 && p<=n+1)
- {
- printf("\Enter new value \n");
- scanf("%d",&v);
- n=Insertion_specification(a,n,v,p);
- printf("\n\n inserted at position %d\n",p);
- }
- else
- {
- printf("\n wrong position \n");
- goto K;
- }
- }
- else
- printf("\n the array is empty \n");
- break;
- case 4: printf("\n Choice = Delete from Array \n");
- if (n!=0)
- {
- Z: printf("\n Enter Position between %d to %d\n",1,n);
- scanf("%d",&p);
- if (p>=1 && p<=n)
- {
- printf("\n Delected value = %d\n", a[p]);
- n=Deletion (a,n,p);
- printf ("\n Delete Sucessfully from position %d\n",p);
- }
- else
- {
- printf("\n Wrong position \n");
- goto Z;
- }
- }
- 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 to search \n");
- break;
- case 6: printf("\n choice =Bubble_short \n");
- if(n!=0)
- Bubble_short(a,n);
- else
- printf("\n The Array is Empty \n");
- break;
- case 7: printf("\n choice = Binary_search \n");
- if (n!=0)
- {
- printf("\n Enter value 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)
- {
- printf("\n Enter new value\n");
- scanf ("%d",&v);
- M: printf ("enter position between %d to %d\n ",1,n);
- scanf("%d",&p);
- if(p>=1&& p<=n)
- edit (a,p,v);
- else {
- printf ("\n wrong position\n");
- goto M;
- }
- }
- else
- printf("No data to edit\n");
- break;
- }
- }
- }
- void display_Array(int b[],int k)
- {
- int j;
- printf("\n the values are:\n");
- for(j=1;j<=k;j++)
- printf("%d\n", b[j]);
- }
- void edit (int b[], int pp ,int vv)
- {
- b[pp]=vv;
- printf("\n edited successfully\n");
- }
- int Insertion_lastpositon (int b[],int nn, int vv)
- {
- b[nn+1]=vv;
- printf("\n Inserted Sucessfully \n\n");
- return nn+1;
- }
- int Insertion_specification (int b[],int nn, int vv,int pp)
- {
- int j;
- for (j=nn;j>=pp;j--)
- b[j+1]=b[j];
- b[pp]=vv;
- return nn+1;
- }
- int Deletion (int b[], int nn, int pp)
- {
- int j;
- for (j=pp; j<nn;j++)
- b[j]=b[j+1];
- return nn-1;
- }
- void linear_search(int b[],int nn, int vv)
- {
- int j,c=0;
- for(j=1;j<=nn;j++)
- {
- if (b[j]==vv)
- {
- printf("\n Found at position =%d \n",j);
- c=c+1;
- }
- }
- if (c==0)
- printf("\n Not Found \n");
- else
- printf("Total Found =%d \n",c);
- }
- void Bubble_short (int b[], int nn)
- {
- int i, j, t;
- for(i=1;i<=nn;i++)
- {
- for(j=1;j<=nn-i;j++)
- {
- if(b[j]>b[j+1])
- {
- t=b[j];
- b[j]=b[j+1];
- b[j+1]=t;
- }
- }
- }
- }
- void Binary_search (int b[],int nn,int vv)
- {
- int beg ,end,mid;
- Bubble_short(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");
- }
Add Comment
Please, Sign In to add comment