nikitast

RK_prep_1

Dec 15th, 2020 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. struct Node
  5. {
  6.     char data;
  7.     Node* next;
  8. };
  9.  
  10. void AddNode(Node*& first, char letter)
  11. {
  12.     Node* cur;
  13.     if (first == NULL)
  14.     {
  15.         first = new Node;
  16.         first->data = letter;
  17.         first->next = NULL;
  18.         cur = first;
  19.     }
  20.     else
  21.     {
  22.         cur = new Node;
  23.         cur->data = letter;
  24.         cur->next = first;
  25.         first = cur;
  26.     }
  27. }
  28.  
  29. void OutputList(Node* first)
  30. {
  31.     while (first != NULL)
  32.     {
  33.         printf("%c ", first->data);
  34.         first = first->next;
  35.     }
  36. }
  37.  
  38. void InsertSymbol(Node*& cur)
  39. {
  40.     Node* symbol = new Node;
  41.     symbol->data = '!';
  42.     symbol->next = cur->next;
  43.     cur->next = symbol;
  44. }
  45.  
  46. void Function(Node*& first)
  47. {
  48.     Node* cur = first;
  49.     if (strchr("aeiouy", cur->data) != NULL)
  50.         AddNode(first, '!');
  51.     while (cur->next != 0)
  52.     {
  53.         if (strchr("aeiouy", cur->next->data) != NULL)
  54.         {
  55.             InsertSymbol(cur);
  56.             cur = cur->next;
  57.         }
  58.         cur = cur->next;
  59.     }
  60. }
  61.  
  62. int main()
  63. {
  64.     const int n = 80;
  65.     char str[n];
  66.     Node* first = NULL, *cur = NULL;
  67.     puts("Enter the string:");
  68.     gets_s(str);
  69.     for (int i = 0; i < strlen(str); i++)
  70.         AddNode(first, str[i]);
  71.     puts("\nFormed list:");
  72.     OutputList(first);
  73.     puts("\n\nExtended list:");
  74.     Function(first);
  75.     OutputList(first);
  76.     return 0;
  77. }
Add Comment
Please, Sign In to add comment