im making this linked (code above) and i need that when the information (country) is the same as the previous information the linked list update only the count and the information is not stored example
if there is this input
mmm 1
mmm 2
mmm 3
output will need to be mmm3
what shoul i do to make this happen
Code:
void insertitem(ListNode **startPtr,booking_type* bookings){
int ans=0;
ListNode *prevNode =NULL ,*curNode=*startPtr;
ListNode *newNode = (ListNode*)malloc(sizeof(ListNode));
strcpy(newNode->data, bookings->country); //newNode->data =bookings->country;
newNode->nextPtr = NULL;
newNode->count = 1;
while ((curNode!=NULL)&&(strcmp(curNode->data,bookings->country)<=0) ) // future : use strcmp
{
if(strcmp(curNode->data,bookings->country)==0){
newNode->count++;
}
prevNode=curNode;
curNode = prevNode->nextPtr;
}
if(prevNode == NULL)
*startPtr=newNode;
else
prevNode->nextPtr = newNode;
newNode->nextPtr = curNode;
}