#include <stdio.h> #include <stdlib.h> #include <string.h> struct node //node creation { char data; struct node *next; }; void remove_adjacent_duplicates(struct node** head_ref) { struct node* current = *head_ref; struct node* cnext = NULL; //the one next to current one int flag=0; cnext = current->next; //storing next //printf("%c %c %d\n",current->data,cnext->data,flag); if(cnext->data==current->data) { flag=1; while(cnext->data==current->data) { cnext=cnext->next; } current=cnext; cnext = current->next; //storing next } else { current=current->next; cnext = current->next; //storing next } //printf("%c %c %d\n",current->data,cnext->data,flag); if(flag) *head_ref = current; } void push(struct node** head_ref, char new_data) { struct node* new_node = (struct node*)malloc(sizeof(struct node)); new_node->data = new_data; new_node->next = *head_ref; *head_ref = new_node; } void printList(struct node* head) { if (head == NULL) { printf("NULL\n\n"); return; } printf("%c->",head->data); printList(head->next); } int main() { char s[100]; int i; struct node* a = NULL; printf("Enter string: "); scanf("%s",s); for(i=strlen(s)-1;i>-1;i--){ push(&a, s[i]); //last in first out, so in reverse g is last but first to come out } printf("\nConverting string to linked list: \n"); printList(a); //printf("%c",current->data); prints first letter of a remove_adjacent_duplicates(&a); printList(a); return 0; }
'false'
'true'
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)