LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C program problem on delete duplicated nodes in linked list ! (https://www.linuxquestions.org/questions/programming-9/c-program-problem-on-delete-duplicated-nodes-in-linked-list-248300/)

antony_csf 10-28-2004 05:05 AM

C program problem on delete duplicated nodes in linked list !
 
I am writting a function to remove duplicated nodes in linked list

but it run out of memory!!

Any C expert can tell me what error on my code!!

many thx
Code:


typedef struct node *NodePtr;

struct node
{
        int num;
        NodePtr next;
};
.
.
.
.
void delete_duplicated_nodes(NodePtr p)
{       
        NodePtr temp_root        = p;
        NodePtr temp_pre        = p;
        NodePtr temp_move        = p->next;


        while(temp_root != NULL){


                while(temp_move != NULL){
                        if(temp_move->num == temp_root->num){
                                temp_move = temp_move->next;               
                                free(temp_pre->next);                               
                                temp_pre->next = temp_move;                       
                        }else{
                                temp_pre = temp_pre->next;                       
                                temp_move = temp_move->next;
                        }
                }


                temp_root        = temp_root->next;                               
                temp_pre        = temp_root->next;                               
                temp_move        = temp_root->next->next;               
        }

}


antony_csf 10-28-2004 05:05 AM

Re: C program problem on delete duplicated nodes in linked list !
 
sorry error post!!:p

itsme86 10-28-2004 10:42 AM

Out of memory? You're not allocating any in your code. What's the exact error you're getting?


All times are GMT -5. The time now is 05:57 PM.