Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <string.h>
- struct Node {
- char data;
- Node* next;
- };
- void AddNode(Node*& first, char symbol)
- {
- if (first == NULL)
- {
- first = new Node;
- first->data = symbol;
- first->next = NULL;
- }
- else
- {
- Node* cur = first;
- first = new Node;
- first->data = symbol;
- first->next = cur;
- }
- }
- void PrintList(Node* first)
- {
- while (first != NULL)
- {
- printf("%c ", first->data);
- first = first->next;
- }
- }
- void ClearMemory(Node*& first)
- {
- while (first != NULL)
- {
- Node* tmp = first;
- first = first->next;
- delete tmp;
- }
- }
- void InsertNodeAfter(Node*& cur, char symbol)
- {
- Node* new_node = new Node;
- new_node->data = symbol;
- new_node->next = cur->next;
- cur->next = new_node;
- }
- void InsertHash(Node* first)
- {
- int cnt = 0;
- while (first->next != NULL)
- {
- cnt++;
- if (cnt % 2 != 0)
- {
- InsertNodeAfter(first, '#');
- first = first->next;
- }
- first = first->next;
- }
- }
- void DeleteNodeAfter(Node*& cur)
- {
- Node* tmp = cur->next;
- cur->next = tmp->next;
- delete tmp;
- }
- void DeleteSymbols(Node* first)
- {
- int cnt = 0;
- while (first->next != NULL)
- {
- cnt++;
- if ((cnt+1) % 3 == 0)
- {
- DeleteNodeAfter(first);
- cnt++;
- }
- if (first->next != NULL)
- first = first->next;
- }
- }
- int main()
- {
- Node* first = NULL;
- char str[80];
- char* ptr;
- puts("Enter the word sequence without spaces:");
- gets_s(str);
- for (int i = 0; i < strlen(str); i++)
- AddNode(first, str[i]);
- puts("\nThe formed list:");
- PrintList(first);
- DeleteSymbols(first);
- puts("\nThe formed list:");
- PrintList(first);
- ClearMemory(first);
- puts("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement