Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<stdio.h>
- #include<stdlib.h>
- struct sequence
- {
- float data;
- struct sequence* link;
- };
- struct sequenceVnesh
- {
- struct sequence* point;
- struct sequenceVnesh* link;
- };
- void changeValue(struct sequence** temp)
- {
- if(*temp == NULL)
- {
- printf("Add new element\n\n");
- }
- else{
- printf("Enter the new value for data:\n\n");
- struct sequence *temp1 = *temp;
- scanf("%f", &temp1 -> data);
- }
- }
- void pointerToBegin(struct sequence** head, struct sequence** temp)
- {
- *temp = *head;
- }
- void skipElem(struct sequence** temp)
- {
- if(*temp == NULL || (*temp) -> link == NULL )
- {
- printf("End's list or add new element\n\n");
- printf("[%d]\n\n",*temp);
- }
- else *temp = (*temp) -> link;
- }
- void showValue( struct sequence** temp)
- {
- struct sequence* temp1 = *temp;
- if(temp1 == NULL) printf("Add new element\n\n");
- else {
- //printf("%f\n\n", (*temp) -> data );
- }
- }
- void makeEmpty(struct sequence** head)
- {
- struct sequence* temp1 = *head;
- struct sequence* temp2;
- while( temp1 != NULL)
- {
- temp2 = temp1 -> link;
- free(temp1);
- temp1 = temp2;
- }
- *head = NULL;
- }
- void beginWork(int* flag)
- {
- *flag = 1;
- }
- void addToEnd(struct sequence** head, struct sequence** temp1){
- struct sequence *temp;
- temp = (struct sequence *) malloc(sizeof(struct sequence));
- printf("Enter the data:\n\n");
- scanf("%f", &temp->data);
- temp->link = NULL;
- if (*head == NULL)
- {
- *head = temp;
- }
- else
- {
- struct sequence *p;
- p = *head;
- while (p->link != NULL)
- {
- p = p->link;
- }
- p->link = temp;
- }
- if(*temp1 == NULL) *temp1 = *head;
- }
- void print(struct sequence** head)
- {
- struct sequence* p;
- p = *head;
- while(p!=NULL)
- {
- printf("%f ", p -> data);
- p = p -> link;
- }
- printf("\n\n");
- if(*head == NULL) printf("List is empty\n\n");
- }
- void over()
- {
- exit(1);
- }
- void isEmpty(struct sequence** head)
- {
- if(*head == NULL) printf("List is empty\n\n");
- else printf("List is not empty\n\n");
- }
- void check(struct sequence** temp)
- {
- if((*temp) -> link == NULL)
- printf("All elements are read\n\n");
- else printf("We have unread elements\n\n");
- }
- void readElem(struct sequence** temp, struct sequence** head)
- {
- if(*head == NULL) printf("List is empty\n\n");
- else {
- printf("Read element: %f\n\n", (*temp)->data);
- if ((*temp)->link == NULL) {
- printf("End's list or add new element\n\n");
- } else {
- *temp = (*temp)->link;
- }
- }
- }
- int main()
- {
- int value;
- int flag = 0;
- struct sequence* head = NULL;
- struct sequence* temp = head;
- while(1)
- {
- printf("1. NAchati raboty.\n");
- printf("2 Sdelati posl pystoi.\n");
- printf("3. Pystaya li posl ?\n");
- printf("4. pokazati znachenie ocherednogo elementa\n");
- printf("5. Propystiti ocherednoi element\n");
- printf("6. Prochitati ocherednoi element posl\n");
- printf("7. Izmeniti znachenie ocherednogo elementa\n");
- printf("8. Dobaviti element v konec\n");
- printf("9. ykazatel ocherednogo element v nachalo\n");
- printf("10 Proveriti - ecti ili net neprochitannie elemnts\n");
- printf("11. Pacpechatati posl \n");
- printf("12. Konec raboty\n\n");
- printf("Vibirite punkt\n");
- scanf("%d",&value);
- switch (value)
- {
- case 1: beginWork(&flag);
- break;
- case 2: if(flag == 1)
- {
- makeEmpty(&head);
- break;
- } else {printf("Nachat raboty\n\n"); break;}
- case 3: if(flag == 1)
- {
- isEmpty(&head);
- break;
- } else {printf("Nachat raboty\n\n"); break;}
- case 4: if(flag == 1)
- {
- showValue(&temp);
- break;
- } else {printf("Nachat raboty\n\n"); break;}
- case 5: if(flag == 1)
- {
- skipElem(&temp);
- break;
- } else {printf("Nachat raboty\n\n"); break;}
- case 6: if(flag == 1)
- {
- readElem(&temp,&head);
- break;
- }
- else {printf("Nachat raboty\n\n"); break;}
- case 7: if(flag == 1)
- {
- changeValue(&temp);
- break;
- } else {printf("Nachat raboty\n\n"); break;}
- case 8: if(flag == 1)
- {
- addToEnd(&head, &temp);
- break;
- } else {printf("Nachat raboty\n\n"); break;}
- case 9: if(flag == 1)
- {
- pointerToBegin(&head, &temp);
- break;
- }else {printf("Nachat raboty\n\n"); break;}
- case 10: if(flag == 1)
- {
- check(&temp);
- break;
- }else {printf("Nachat raboty\n\n"); break;}
- case 11: if(flag == 1)
- {
- print(&head);
- break;
- } else {printf("Nachat raboty\n\n"); break;}
- case 12: if(flag == 1) over();
- else {printf("Nachat raboty\n\n"); break;}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement