Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <stdio.h>
- #include <ctype.h>
- #include <math.h>
- #include <stdlib.h>
- #include <string>
- #include <conio.h>
- typedef struct list
- {
- int value;
- struct list *next;
- } list;
- int main()
- {
- char str[100], buf[100];
- int j, g, key, z;
- j = 0;
- g = 0;
- key = 0;
- list *head = new list;
- list *fe = new list;
- list *sort = new list;
- list *zen = new list;
- printf("Please, input some numbers.\n");
- gets_s(str);
- for (int i = 0; i <= strlen(str); i++)
- {
- if (isdigit(str[i]) || str[i] == '-')
- {
- buf[j] = str[i];
- j++;
- }
- else
- {
- list *nextitem = new list;
- head->value = atoi(buf);
- head->next = nextitem;
- if (g == 0)
- {
- fe = head;
- sort = head;
- zen = head;
- }
- head = nextitem;
- memset(&buf[0], 0, sizeof(buf));
- j = 0;
- g++;
- }
- }
- printf("Your sorted numbers:\n");
- for (int i = 0; i < g; i++)
- {
- for (int j = 0; j < g - 1; j++)
- {
- if (abs(sort->value) < abs(sort->next->value))
- {
- z = sort->value;
- sort->value = sort->next->value;
- sort->next->value = z;
- }
- sort = sort->next;
- }
- sort = fe;
- }
- for (int i = 0; i < g; i++)
- {
- printf("%d ", sort->value);
- sort = sort->next;
- }
- printf("\nPlease, print the number you want to add:\n");
- gets_s(str);
- for (int i = 0; i <= strlen(str); i++)
- {
- if (isdigit(str[i]))
- {
- buf[j] = abs(str[i]);
- j++;
- }
- else
- {
- list *nextitem = new list;
- head->value = atoi(buf);
- head->next = nextitem;
- head = nextitem;
- memset(&buf[0], 0, sizeof(buf));
- j = 0;
- g++;
- }
- }
- printf("Please, print the number you want to delete.\n");
- scanf_s("%d", &z);
- list *previtem = new list;
- while (zen != head)
- {
- if (key == 0)
- {
- if (z == zen->value)
- {
- previtem->next = zen->next;
- delete(zen);
- zen = previtem->next;
- g = g - 1;
- key = 1;
- break;
- }
- previtem = zen;
- zen = zen->next;
- }
- }
- if (key == 0)
- {
- printf("Input another z to delete the element.");
- }
- sort = fe;
- for (int i = 0; i < g; i++)
- {
- for (int j = 0; j < g - 1; j++)
- {
- if (abs(sort->value) < abs(sort->next->value))
- {
- z = sort->value;
- sort->value = sort->next->value;
- sort->next->value = z;
- }
- sort = sort->next;
- }
- sort = fe;
- }
- printf("\nResult:\n");
- for (int i = 0; i < g; i++)
- {
- printf("%d ", fe->value);
- fe = fe->next;
- }
- getchar();
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement