Appending unique values only in a linked list in C
        Posted  
        
            by LuckySlevin
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by LuckySlevin
        
        
        
        Published on 2010-05-15T13:14:33Z
        Indexed on 
            2010/05/15
            13:24 UTC
        
        
        Read the original article
        Hit count: 295
        
typedef struct child {int count; char word[100]; inner_list*next;} child;
typedef struct parent
{ char data [100];
inner_list * head;
int count;
outer_list * next; } parent;
void append(child **q,char num[100],int size)
{   child *temp,*r,*temp2,*temp3;
parent *out=NULL;
  temp = *q;
  temp2 = *q;
  temp3 = *q;
  char *str;
  if(*q==NULL)
  {   temp = (child *)malloc(sizeof(child));
    strcpy(temp->word,num);
    temp->count =size;
    temp->next=NULL;
    *q=temp;
  }
  else
  {  temp = *q;
   while(temp->next !=NULL)
   {  temp=temp->next;
   }
   r = (child *)malloc(sizeof(child));
   strcpy(r->word,num);
   r->count = size;
   r->next=NULL;
   temp->next=r;
  }
}
This is my append function which I use for adding an element to my child list. But my problem is it only should append unique values which are followed by a string. Which means :
Inputs :  aaa bbb aaa ccc aaa bbb ccc aaa
Append should act :
For aaa string there  should be a list like bbb->ccc(Not bbb->ccc->bbb since bbb is already there if bbb is coming more than one time it should be increase count only.)
For bbb string there should be list like aaa->ccc only
For ccc string there should be list like aaa only
I hope i could make myself clear. Is there any ideas? Please ask for further info.
© Stack Overflow or respective owner