Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- typedef struct Node
- {
- int value;
- struct Node* next;
- } Spisok;
- int getSize() {
- int ind;
- int size;
- int flag;
- do {
- do {
- rewind(stdin);
- printf("Enter the size of the list\n");
- ind = scanf_s("%d", &size);
- if (ind != 1) {
- printf("Incorrect input!!!\n");
- }
- } while (ind != 1);
- if ((size > 20) || (size < 1))
- {
- printf("Enter the size between 1 and 20");
- flag = 1;
- }
- else {
- flag = 0;
- }
- } while (flag == 1);
- return size;
- }
- int getNumber(int i) {
- int ind;
- int num;
- int flag;
- do {
- do {
- rewind(stdin);
- printf("Enter element number %d: ", i + 1, "\n");
- ind = scanf_s("%d", &num);
- if (ind != 1) {
- printf("Incorrect input!!!\n");
- }
- } while (ind != 1);
- if ((num > 50) || (num < -50))
- {
- printf("Enter the number, which is higher than -50 and lower than 50\n");
- flag = 1;
- }
- else {
- flag = 0;
- }
- } while (flag == 1);
- return num;
- }
- Spisok* create(int data)
- {
- Spisok* tmp = (Spisok*)malloc(sizeof(Spisok));
- tmp->value = data;
- tmp->next = NULL;
- return(tmp);
- }
- void add_element_end(int data, Spisok* head)
- {
- Spisok* tmp = (Spisok*)malloc(sizeof(Spisok));
- tmp->value = data;
- tmp->next = NULL;
- Spisok* p = head;
- while (p->next != NULL)
- p = p->next;
- p->next = tmp;
- }
- Spisok* remove_all(Spisok* head)
- {
- while (head != NULL)
- {
- Spisok* p = head;
- head = head->next;
- free(p);
- }
- return NULL;
- }
- void outputList(Spisok* tmp) {
- while (tmp != NULL)
- {
- printf("%d ", tmp->value);
- tmp = tmp->next;
- }
- }
- int main() {
- int size = 0;
- int num = 0;
- size = getSize();
- num = getNumber(0);
- Spisok* myList = create(num);
- for (int i = 1; i < size; i++) {
- num = getNumber(i);
- add_element_end(num, myList);
- }
- outputList(myList);
- remove_all(myList);
- printf("\n\n\n\n%d", 13 - 23 % 13);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement