SHARE
TWEET

Untitled

a guest Feb 27th, 2020 83 in 137 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4.  
  5. struct List {
  6.     char value;
  7.     List* next;
  8. };
  9.  
  10. List* Ins_last(List* head, char n)
  11. {
  12.     List* q = (List*)malloc(sizeof(List)), * t;
  13.     q->value = n;
  14.     q->next = NULL;
  15.     t = head;
  16.     while (t->next != NULL)
  17.         t = t->next;
  18.     t->next = q;
  19.     return head;
  20. }
  21.  
  22. void free_List(List* head) {
  23.     List* t;
  24.     t = head;
  25.     List* r;
  26.     while (t->next != NULL)
  27.     {
  28.         r = t;
  29.         t = t->next;
  30.         free(r);
  31.     }
  32. }
  33.  
  34.  
  35. void write(List* head)
  36. {
  37.     char m = 0;
  38.     char buffer[10] = { 0 };
  39.  
  40.     printf("Enter in the symbols. Enter each next symbols from a new line\n");
  41.  
  42.     while (buffer[0] != '\n')
  43.     {
  44.         fgets(buffer, 10, stdin);
  45.         if (m == 0)
  46.             head->value = *buffer;
  47.         else Ins_last(head, *buffer);
  48.         m++;
  49.     }
  50. }
  51.  
  52. void list_print(List* head) {
  53.     List* t;
  54.     t = head;
  55.     List* r;
  56.     while (t->next != NULL)
  57.     {
  58.         printf("\n%c", t->value);
  59.         t = t->next;
  60.     }
  61. }
  62.  
  63. void deleter_of_repeat(List* head)
  64. {
  65.     List* t;
  66.     t = head;
  67.     List* r;
  68.     List* a;
  69.     r = t->next;
  70.     a = t;
  71.     int count=0;
  72.  
  73.     while (t->next != NULL)
  74.     {
  75.         if (t->value == r->value)
  76.         {
  77.             a->next = r->next;
  78.             count++;
  79.         }
  80.         else a = t->next;
  81.  
  82.         t = a;
  83.         r = t->next;
  84.     }
  85.     printf("Count of deleted value %d", count);
  86. }
  87.  
  88. int main(void) {
  89.     List* head = (List*)malloc(sizeof(List));
  90.     head->next = NULL;
  91.     write(head);
  92.     deleter_of_repeat(head);
  93.     printf("\nList with out symbols repeat: \n");
  94.     list_print(head);
  95.     free_List(head);
  96. }
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