SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
Remove duplicates from a sorted linked list
Remove duplicates from a sorted linked list
#include
#include
struct node { int data; struct node *next; }; struct node* newnode(int data) { struct node *new=(struct node*)malloc(sizeof(struct node)); new->data=data; new->next=NULL; return new; } void insertashead(struct node **head,int data) { struct node *temp=newnode(data); if((*head)==NULL) *head=temp; else { temp->next=(*head); (*head)=temp; } } void printlist(struct node *head) { while(head!=NULL) { printf("%d ",head->data); head=head->next; } } void removeduplicates(struct node *head) { struct node *current=head; struct node *temp; while(current->next!=NULL) { while(current->data==current->next->data) { temp=current->next; current->next=temp->next; free(temp); } current=current->next; } } int main(void) { struct node *head=NULL; int n,x,i,key; scanf("%d",&n); for(i=0;i
PREVIOUS
NEXT
HOME