mercredi 29 mai 2019

Looping through linked lists

So basically, what I'm trying to do is going through all the nodes and verify if node.value is <= cost. If it is I need to remove that node and in the end I want to store the nodes that weren't remove in a new struct. I'm not sure how exactly am I supose to do this.

This struct can be an example:

struct node {
    int value;
    node * next;
}

I'm going through all the nodes and remove only the ones that doen't have the required.

node * verify_money(node * head, int cost)
{

    node * iterator = head;

    while(iterator != NULL){
       if(iterator.value <= cost) {  
           /*remove this node*/
       }
       iterator = iterator.next;
    }

return /*struct without nodes removed)/*

}

I want to get the remaining nodes.

Aucun commentaire:

Enregistrer un commentaire