Advertisement
Rakibul_Ahasan

Array_Manipulation

Aug 22nd, 2019
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define Max_Size 100
  4.  
  5. int arr[Max_Size];
  6. int last=0;
  7.  
  8. void insert(int value)
  9. {
  10.     arr[last]=value;
  11.     last++;
  12. }
  13.  
  14. void printlist()
  15. {
  16.     for(int i=0;i<last;i++)
  17.         printf("The Array List:%d ",arr[i]);
  18.         printf("\n");
  19. }
  20.  
  21. int search(int value)
  22. {
  23.     int i;
  24.     for(i=0;i<last;i++)
  25.     {
  26.         if(arr[i]==value)
  27.             return 1;
  28.     }
  29.  
  30.     return 0;
  31. }
  32.  
  33. void deleteval(int value)
  34. {
  35.     int i,pos=-1;
  36.     for(i=0;i<last;i++)
  37.     {
  38.         if(arr[i]==value)
  39.         {
  40.             pos=i;
  41.             break;
  42.         }
  43.     }
  44.  
  45.     if(pos>=0)
  46.     {
  47.         for(i=pos+1;i<last;i++)
  48.         {
  49.             arr[i-1]=arr[i];
  50.         }
  51.         last--;
  52.         printf("%d value deleted\n\n",value);
  53.     }
  54.     else
  55.         printf("%d value not found\n\n",value);
  56. }
  57.  
  58. void menu () {
  59.      while (1) {
  60.         printf("Press 1 to insert.\n");
  61.         printf("Press 2 to search.\n");
  62.         printf("Press 3 to delete node.\n");
  63.         printf("Press 4 to print list.\n");
  64.         printf("Press 0 to Exit.\n");
  65.         printf("\n");
  66.  
  67.         int n;
  68.         scanf("%d", &n);
  69.  
  70.         if (n==0) break;
  71.  
  72.         else if (n==1) {
  73.             printf("Enter the number: ");
  74.             int num;
  75.             scanf("%d", &num);
  76.             printf("\n");
  77.  
  78.             insert(num);
  79.         }
  80.  
  81.         else if (n==2) {
  82.             printf("Enter the number: ");
  83.             int num;
  84.             scanf("%d", &num);
  85.             printf("\n");
  86.  
  87.             if (search(num)) printf("The Number is found.\n\n");
  88.             else printf("The Number is Not found.\n\n");
  89.         }
  90.  
  91.         else if (n==3) {
  92.             printf("Enter the number: ");
  93.             int num;
  94.             scanf("%d", &num);
  95.             printf("\n");
  96.  
  97.             deleteval(num) ;
  98.         }
  99.  
  100.         else if (n==4) printlist();
  101.  
  102.         else {
  103.             printf("Invalid choice! Try again.\n\n");
  104.         }
  105.     }
  106. }
  107.  
  108. int main () {
  109.     menu();
  110.     return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement