Advertisement
Guest User

ss

a guest
Dec 9th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.85 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. #include<stdio.h>
  5. #include<stdlib.h>
  6.  
  7. struct sequence
  8. {
  9.     float data;
  10.     struct sequence* link;
  11. };
  12. struct sequenceVnesh
  13. {
  14.     struct sequence* point;
  15.     struct sequenceVnesh* link;
  16. };
  17.  
  18. void changeValue(struct sequence** temp)
  19. {
  20.     if(*temp == NULL)
  21.     {
  22.         printf("Add new element\n\n");
  23.     }
  24.     else{
  25.         printf("Enter the new value for data:\n\n");
  26.         struct sequence *temp1 = *temp;
  27.         scanf("%f", &temp1 -> data);
  28.     }
  29. }
  30.  
  31. void pointerToBegin(struct sequence** head, struct sequence** temp)
  32. {
  33.     *temp = *head;
  34. }
  35.  
  36. void skipElem(struct sequence** temp)
  37. {
  38.    
  39.     if(*temp == NULL || (*temp) -> link == NULL )
  40.     {
  41.         printf("End's list or add new element\n\n");
  42.         printf("[%d]\n\n",*temp);
  43.     }
  44.     else *temp = (*temp) -> link;
  45. }
  46.  
  47. void showValue( struct sequence** temp)
  48. {
  49.     struct sequence* temp1 = *temp;
  50.     if(temp1 == NULL) printf("Add new element\n\n");
  51.     else  {
  52.         //printf("%f\n\n",  (*temp) -> data );
  53.     }
  54.    
  55. }
  56.  
  57. void makeEmpty(struct sequence** head)
  58. {
  59.     struct sequence* temp1 = *head;
  60.     struct sequence* temp2;
  61.     while( temp1 != NULL)
  62.     {
  63.         temp2 = temp1 -> link;
  64.         free(temp1);
  65.         temp1 = temp2;
  66.     }
  67.     *head = NULL;
  68. }
  69.  
  70. void  beginWork(int* flag)
  71. {
  72.     *flag =  1;
  73. }
  74.  
  75. void addToEnd(struct sequence** head, struct sequence** temp1){
  76.    
  77.    
  78.     struct sequence *temp;
  79.     temp = (struct sequence *) malloc(sizeof(struct sequence));
  80.    
  81.     printf("Enter the data:\n\n");
  82.     scanf("%f", &temp->data);
  83.    
  84.     temp->link = NULL;
  85.    
  86.     if (*head == NULL)
  87.     {
  88.         *head = temp;
  89.     }
  90.     else
  91.     {
  92.         struct sequence *p;
  93.        
  94.         p = *head;
  95.        
  96.         while (p->link != NULL)
  97.         {
  98.             p = p->link;
  99.         }
  100.        
  101.         p->link = temp;
  102.     }
  103.     if(*temp1 == NULL) *temp1 = *head;
  104. }
  105.  
  106. void print(struct sequence** head)
  107. {
  108.     struct sequence* p;
  109.     p = *head;
  110.    
  111.     while(p!=NULL)
  112.     {
  113.         printf("%f  ", p -> data);
  114.         p = p -> link;
  115.     }
  116.     printf("\n\n");
  117.     if(*head == NULL) printf("List is empty\n\n");
  118. }
  119.  
  120. void over()
  121. {
  122.     exit(1);
  123. }
  124.  
  125. void isEmpty(struct sequence** head)
  126. {
  127.     if(*head == NULL) printf("List is empty\n\n");
  128.     else printf("List is not empty\n\n");
  129. }
  130.  
  131. void check(struct sequence** temp)
  132. {
  133.     if((*temp) -> link == NULL)
  134.         printf("All elements are read\n\n");
  135.     else printf("We have unread elements\n\n");
  136. }
  137.  
  138. void readElem(struct sequence** temp, struct sequence** head)
  139. {
  140.    
  141.     if(*head == NULL) printf("List is empty\n\n");
  142.     else {
  143.         printf("Read element: %f\n\n", (*temp)->data);
  144.         if ((*temp)->link == NULL) {
  145.             printf("End's list or add new element\n\n");
  146.         } else {
  147.            
  148.             *temp = (*temp)->link;
  149.            
  150.         }
  151.     }
  152.    
  153. }
  154.  
  155. int main()
  156. {
  157.     int value;
  158.     int flag = 0;
  159.    
  160.     struct sequence* head = NULL;
  161.     struct sequence* temp = head;
  162.    
  163.     while(1)
  164.     {
  165.        
  166.         printf("1.  NAchati raboty.\n");
  167.         printf("2   Sdelati posl pystoi.\n");
  168.         printf("3.  Pystaya li posl ?\n");
  169.         printf("4.  pokazati znachenie ocherednogo elementa\n");
  170.         printf("5.  Propystiti ocherednoi element\n");
  171.         printf("6.  Prochitati ocherednoi element posl\n");
  172.         printf("7.  Izmeniti znachenie ocherednogo elementa\n");
  173.         printf("8.  Dobaviti element v konec\n");
  174.         printf("9.  ykazatel ocherednogo element v nachalo\n");
  175.         printf("10  Proveriti - ecti ili net neprochitannie elemnts\n");
  176.         printf("11. Pacpechatati posl \n");
  177.         printf("12. Konec raboty\n\n");
  178.        
  179.         printf("Vibirite punkt\n");
  180.         scanf("%d",&value);
  181.        
  182.         switch (value)
  183.         {
  184.             case 1: beginWork(&flag);
  185.                 break;
  186.                
  187.             case 2: if(flag == 1)
  188.             {
  189.                 makeEmpty(&head);
  190.                 break;
  191.             } else {printf("Nachat raboty\n\n"); break;}
  192.                
  193.             case 3: if(flag == 1)
  194.             {
  195.                 isEmpty(&head);
  196.                 break;
  197.             } else  {printf("Nachat raboty\n\n"); break;}
  198.                
  199.             case 4: if(flag == 1)
  200.             {
  201.                 showValue(&temp);
  202.                 break;
  203.             } else  {printf("Nachat raboty\n\n"); break;}
  204.                
  205.             case 5: if(flag == 1)
  206.             {
  207.                 skipElem(&temp);
  208.                 break;
  209.             } else  {printf("Nachat raboty\n\n"); break;}
  210.                
  211.             case 6:  if(flag == 1)
  212.             {
  213.                 readElem(&temp,&head);
  214.                 break;
  215.             }
  216.             else  {printf("Nachat raboty\n\n"); break;}
  217.             case 7: if(flag == 1)
  218.             {
  219.                 changeValue(&temp);
  220.                 break;
  221.             } else  {printf("Nachat raboty\n\n"); break;}
  222.                
  223.             case 8: if(flag == 1)
  224.             {
  225.                 addToEnd(&head, &temp);
  226.                 break;
  227.             }   else  {printf("Nachat raboty\n\n"); break;}
  228.             case 9: if(flag == 1)
  229.             {
  230.                 pointerToBegin(&head, &temp);
  231.                 break;
  232.             }else  {printf("Nachat raboty\n\n"); break;}
  233.                
  234.             case 10: if(flag == 1)
  235.             {
  236.                 check(&temp);
  237.                 break;
  238.             }else  {printf("Nachat raboty\n\n"); break;}
  239.                
  240.             case 11: if(flag == 1)
  241.             {
  242.                 print(&head);
  243.                 break;
  244.             } else {printf("Nachat raboty\n\n"); break;}
  245.                
  246.             case 12: if(flag == 1) over();
  247.             else {printf("Nachat raboty\n\n"); break;}
  248.                
  249.         }
  250.     }
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement