Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #define size 5
- int insert();
- int rem();
- int get();
- int find();
- int update();
- int len();
- int print();
- int item[size], length=0,current=-1;
- int main()
- {
- int i, choice;
- for(;;)
- {
- printf("\n\nInsert any \n");
- printf("1. Insert\n");
- printf("2. Remove \n");
- printf("3. Get \n");
- printf("4. find\n");
- printf("5. Update\n");
- printf("6. length \n");
- printf("7. Print \n");
- printf("0. Quit \n\t");
- scanf("%d",&choice);
- switch(choice)
- {
- case 1:
- insert();
- break;
- case 2:
- rem();
- break;
- case 3:
- get();
- break;
- case 4:
- find();
- break;
- case 5:
- update();
- break;
- case 6:
- len();
- break;
- case 7:
- print();
- break;
- case 0:
- exit(0);
- break;
- default:
- break;
- }
- }
- }
- int insert()
- {
- if(length<size)
- {
- current++;
- printf("Enter the value ==>");
- scanf("%d",&item[current]);
- length=length+1;
- }
- else
- printf("\n\tOverflow\n");
- }
- int rem()
- {
- if(length>0)
- {
- current--;
- length--;
- }
- else
- printf("\n\tUnderflow\n");
- }
- int get()
- {
- printf("\nCurrent value:\t%d\n",item[current]);
- }
- int find()
- {
- int value,i;
- printf("value:");
- scanf("%d",&value);
- for(i=0;i<length;i++)
- {
- if(item[i]==value)
- {
- printf("\nIndex=%d",i);
- }
- }
- }
- int update()
- {
- int index,value;
- printf("Index=");
- scanf("%d",&index);
- printf("\nNew Value=");
- scanf("%d",&value);
- item[index]=value;
- }
- int len()
- {
- printf("Length=%d",length);
- }
- int print()
- {
- int i;
- printf("\n\nThe array is: \n");
- for(i=0;i<length;i++)
- printf("%d ",item[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment