Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #define Max_Size 100
- int arr[Max_Size];
- int last=0;
- void insert(int value)
- {
- arr[last]=value;
- last++;
- }
- void printlist()
- {
- for(int i=0;i<last;i++)
- printf("The Array List:%d ",arr[i]);
- printf("\n");
- }
- int search(int value)
- {
- int i;
- for(i=0;i<last;i++)
- {
- if(arr[i]==value)
- return 1;
- }
- return 0;
- }
- void deleteval(int value)
- {
- int i,pos=-1;
- for(i=0;i<last;i++)
- {
- if(arr[i]==value)
- {
- pos=i;
- break;
- }
- }
- if(pos>=0)
- {
- for(i=pos+1;i<last;i++)
- {
- arr[i-1]=arr[i];
- }
- last--;
- printf("%d value deleted\n\n",value);
- }
- else
- printf("%d value not found\n\n",value);
- }
- void menu () {
- while (1) {
- printf("Press 1 to insert.\n");
- printf("Press 2 to search.\n");
- printf("Press 3 to delete node.\n");
- printf("Press 4 to print list.\n");
- printf("Press 0 to Exit.\n");
- printf("\n");
- int n;
- scanf("%d", &n);
- if (n==0) break;
- else if (n==1) {
- printf("Enter the number: ");
- int num;
- scanf("%d", &num);
- printf("\n");
- insert(num);
- }
- else if (n==2) {
- printf("Enter the number: ");
- int num;
- scanf("%d", &num);
- printf("\n");
- if (search(num)) printf("The Number is found.\n\n");
- else printf("The Number is Not found.\n\n");
- }
- else if (n==3) {
- printf("Enter the number: ");
- int num;
- scanf("%d", &num);
- printf("\n");
- deleteval(num) ;
- }
- else if (n==4) printlist();
- else {
- printf("Invalid choice! Try again.\n\n");
- }
- }
- }
- int main () {
- menu();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement