Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- //FUNCTION DECLARATION
- void DisplayArray(int b[],int k);
- void Edit(int b[], int pp, int vv);
- int InsertLastPos(int b[],int nn,int vv);
- int Inserttion_SpecificPos(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("Enter How Many Values: \n");
- scanf("%d",&n);
- printf("Enter Values:");
- for (i=1; i<=n; i++)
- scanf("%d", &a[i]);
- while(b)
- {
- printf("--------Menu--------\n");
- printf("\nPress 1 for Display \n");
- printf("\nPress 2 for Insertion at Last Point \n");
- printf("\nPress 3 for Insertion at Specific Point \n");
- printf("\nPress 4 for Delete from Specific Position \n");
- printf("\nPress 5 for Linear Search \n");
- printf("\nPress 6 Bubble Sort \n");
- printf("\nPress 7 for Binary Search \n");
- printf("\nPress 8 for Edit \n");
- printf("\nPress 0 for Quit \n");
- printf("\nEnter Your Choice: ");
- scanf("%d",&c);
- switch (c)
- {
- //QUIT
- case 0: b=0;
- break;
- //DISPLAY
- case 1:
- printf("\n You have Choiced Display\n");
- if(n!=0)
- DisplayArray(a,n);
- else
- printf("\n There Are No Data to Display\n ");
- break;
- //INSERTION AT LAST POSITION
- case 2:
- printf("\nYou Have Choiced Insert at Last Postition\n");
- printf("\nEnter Value\n");
- scanf("%d",&v);
- n = InsertLastPos(a,n,v);
- break;
- //Insertion at spcific Position
- case 3: printf("\n choice= insertion at specifition\n");
- if(n!=0)
- {
- k: printf("\n Enter position between %d to %d \n", 1, n+1);
- scanf ("%d",&p);
- if (p>=1 && p<=n+1)
- {
- printf("\n Enter new valu \n");
- scanf("%d",&v);
- {
- printf("\ninsartion value is=%d\n",v);
- n=Inserttion_SpecificPos(a,n,v,p);
- printf("\n insartion position is %d\n",p);
- }
- }
- else
- {
- printf("\n wrong position \n");
- goto k;
- }
- }
- else
- printf ("\n the array is emptu \n");
- break;
- //delete
- case 4:
- printf("\n choice= Delete form 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("\ndeleted value is=%d\n",a[p]);
- n=deletion(a,n,p);
- printf("\n deleted position is %d\n",p);
- }
- else
- {
- printf("\n wrong position \n");
- goto z;
- }
- }
- else
- printf("\n no data to delete \n");
- break;
- //EDIT
- case 8:
- printf("\nYou have Choiced Edit");
- if(n!=0)
- {
- printf("\nEnter 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("\nWrong Position\n");
- goto M;
- }
- }
- else
- printf("\nNo Data to Edit\n");
- break;
- default: printf("\n Wrong Choice \n");
- break;
- }
- }
- return 0;
- }
- //Dfinition of Function
- //Display
- void DisplayArray(int b[],int k)
- {
- int j;
- printf("\n The values are:\n");
- for (j=1; j<=k; j++)
- printf("%d\n",b[j]);
- }
- //Edit
- void Edit(int b[], int pp, int vv)
- {
- b[pp]=vv;
- printf("\nEdited Successfully\n");
- }
- //Insertion at Last Position
- int InsertLastPos(int b[],int nn,int vv)
- {
- b[nn+1]=vv;
- printf("\nInserted Successfully\n");
- return nn+1;
- }
- //Insertion at spcific Position
- int Inserttion_SpecificPos(int b[],int nn, int vv,int pp)
- {
- int j;
- for (j=nn; j>=pp; j--)
- b[j+1]=b[j];
- b[pp]=vv;
- printf("\n insertion is sucessfull\n");
- return nn+1;
- }
- //delete at position
- int deletion (int b[],int nn, int pp)
- {
- int j;
- for (j=pp; j<nn; j++)
- b[j]=b[j+1];
- printf("\n Delete is sucessfull\n");
- return nn-1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement