Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct Node
- {
- char data;
- struct Node* next;
- } node;
- node* create_node(char data)
- {
- node* temp = (node*)malloc(sizeof(node));
- temp->data = data;
- temp->next = NULL;
- return temp;
- }
- void insert(node** head, char data)
- {
- node* temp = *head;
- node* link = create_node(data);
- if (*head == NULL)
- {
- *head = link;
- return;
- }
- while (temp != NULL)
- {
- if (temp->next == NULL)
- {
- temp->next = link;
- return;
- }
- else
- temp = temp->next;
- }
- }
- void print_list(node* head)
- {
- if (head == NULL)
- {
- printf("List is empty\n");
- return;
- }
- node* temp = head;
- while (temp != NULL)
- {
- printf("%c->", temp->data);
- temp = temp->next;
- }
- if (temp == NULL)
- printf("NULL");
- }
- void remove_duplications(node** head)
- {
- // a>a>a>b>b>b>N
- node* i = *head;
- node* j, * temp;
- while (i->next != NULL)
- {
- j = i;
- while (j->next != NULL)
- {
- if (j->next->data == i->data)
- {
- temp = j->next;
- j->next = j->next->next;
- free(temp);
- }
- else if (j->next != NULL)
- j = j->next;
- else
- break;
- }
- if (i->next)
- i = i->next;
- else
- break;
- }
- }
- void main()
- {
- node* head = NULL;
- print_list(head);
- /*insert(&head, 'a');
- insert(&head, 'b');
- insert(&head, 'd');
- insert(&head, 'b');
- insert(&head, 'c');
- insert(&head, 'c');*/
- /*insert(&head, 'a');
- insert(&head, 'a');
- insert(&head, 'b');
- insert(&head, 'b');
- insert(&head, 'c');
- insert(&head, 'a');*/
- insert(&head, 'a');
- insert(&head, 'b');
- insert(&head, 'b');
- insert(&head, 'a');
- insert(&head, 'b');
- insert(&head, 'b');
- /*insert(&head, 'a');
- insert(&head, 'a');
- insert(&head, 'a');
- insert(&head, 'b');
- insert(&head, 'b');
- insert(&head, 'b');*/
- remove_duplications(&head);
- print_list(head);
- }
Add Comment
Please, Sign In to add comment