Advertisement
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);
- 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 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement