daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <ctype.h>
  5. #include <math.h>
  6. #include <stdlib.h>
  7. #include <string>
  8. #include <conio.h>
  9.  
  10. typedef struct list
  11.  
  12. {
  13.  
  14. int value;
  15.  
  16. struct list *next;
  17.  
  18. } list;
  19.  
  20. int main()
  21.  
  22. {
  23.  
  24. char str[100], buf[100];
  25.  
  26. int j, g, key, z;
  27.  
  28. j = 0;
  29.  
  30. g = 0;
  31.  
  32. key = 0;
  33.  
  34. list *head = new list;
  35.  
  36. list *fe = new list;
  37.  
  38. list *sort = new list;
  39.  
  40. list *zen = new list;
  41.  
  42. printf("Please, input some numbers.\n");
  43.  
  44. gets_s(str);
  45.  
  46. for (int i = 0; i <= strlen(str); i++)
  47.  
  48. {
  49.  
  50. if (isdigit(str[i]) || str[i] == '-')
  51.  
  52. {
  53.  
  54. buf[j] = str[i];
  55.  
  56. j++;
  57.  
  58. }
  59.  
  60. else
  61.  
  62. {
  63.  
  64. list *nextitem = new list;
  65.  
  66. head->value = atoi(buf);
  67.  
  68. head->next = nextitem;
  69.  
  70. if (g == 0)
  71.  
  72. {
  73.  
  74. fe = head;
  75.  
  76. sort = head;
  77.  
  78. zen = head;
  79.  
  80. }
  81.  
  82. head = nextitem;
  83.  
  84. memset(&buf[0], 0, sizeof(buf));
  85.  
  86. j = 0;
  87.  
  88. g++;
  89.  
  90. }
  91.  
  92. }
  93.  
  94. printf("Your sorted numbers:\n");
  95.  
  96. for (int i = 0; i < g; i++)
  97.  
  98. {
  99.  
  100. for (int j = 0; j < g - 1; j++)
  101.  
  102. {
  103.  
  104. if (abs(sort->value) < abs(sort->next->value))
  105.  
  106. {
  107.  
  108. z = sort->value;
  109.  
  110. sort->value = sort->next->value;
  111.  
  112. sort->next->value = z;
  113.  
  114. }
  115.  
  116. sort = sort->next;
  117.  
  118. }
  119.  
  120. sort = fe;
  121.  
  122. }
  123.  
  124. for (int i = 0; i < g; i++)
  125.  
  126. {
  127.  
  128. printf("%d ", sort->value);
  129.  
  130. sort = sort->next;
  131.  
  132. }
  133.  
  134. printf("\nPlease, print the number you want to add:\n");
  135.  
  136. gets_s(str);
  137.  
  138. for (int i = 0; i <= strlen(str); i++)
  139.  
  140. {
  141.  
  142. if (isdigit(str[i]))
  143.  
  144. {
  145.  
  146. buf[j] = abs(str[i]);
  147.  
  148. j++;
  149.  
  150. }
  151.  
  152. else
  153.  
  154. {
  155.  
  156. list *nextitem = new list;
  157.  
  158. head->value = atoi(buf);
  159.  
  160. head->next = nextitem;
  161.  
  162. head = nextitem;
  163.  
  164. memset(&buf[0], 0, sizeof(buf));
  165.  
  166. j = 0;
  167.  
  168. g++;
  169.  
  170. }
  171.  
  172. }
  173.  
  174. printf("Please, print the number you want to delete.\n");
  175.  
  176. scanf_s("%d", &z);
  177.  
  178. list *previtem = new list;
  179.  
  180. while (zen != head)
  181.  
  182. {
  183.  
  184. if (key == 0)
  185.  
  186. {
  187.  
  188. if (z == zen->value)
  189.  
  190. {
  191.  
  192. previtem->next = zen->next;
  193.  
  194. delete(zen);
  195.  
  196. zen = previtem->next;
  197.  
  198. g = g - 1;
  199.  
  200. key = 1;
  201.  
  202. break;
  203.  
  204. }
  205.  
  206. previtem = zen;
  207.  
  208. zen = zen->next;
  209.  
  210. }
  211.  
  212. }
  213.  
  214. if (key == 0)
  215.  
  216. {
  217.  
  218. printf("Input another z to delete the element.");
  219.  
  220. }
  221.  
  222. sort = fe;
  223.  
  224. for (int i = 0; i < g; i++)
  225.  
  226. {
  227.  
  228. for (int j = 0; j < g - 1; j++)
  229.  
  230. {
  231.  
  232. if (abs(sort->value) < abs(sort->next->value))
  233.  
  234. {
  235.  
  236. z = sort->value;
  237.  
  238. sort->value = sort->next->value;
  239.  
  240. sort->next->value = z;
  241.  
  242. }
  243.  
  244. sort = sort->next;
  245.  
  246. }
  247.  
  248. sort = fe;
  249.  
  250. }
  251.  
  252. printf("\nResult:\n");
  253.  
  254. for (int i = 0; i < g; i++)
  255.  
  256. {
  257.  
  258. printf("%d ", fe->value);
  259.  
  260. fe = fe->next;
  261.  
  262. }
  263.  
  264. getchar();
  265. getchar();
  266.  
  267. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top