nodes linked listed and such 
Author Message
 nodes linked listed and such

I am trying to figure out an exercise that wants me to  delete 3 types of
nodes, head node, tail node and middle node of a linked list.  It makes no
sense to me  (newbie)

the setup is

typedef struct node
{
    int value;                            /* value of node */
    struct node next;               /* points to next node in list */
    struct node previous        /* points to previous node in list */
 }NodeRec;

typedef  NodeRec *node_ptr;

The foward pointers follow the node values in sorted order from smallest to
largest.  The backwards pointer points to each nodes predecessor as
determined by the sorted ordering

I need to create a function   test = remove(item,head,tail);

I've been working on this type of example for days and I must be really
stupid because I just don't understand it.  I'd appreciate any answers

Thanks

Jim

--



Sat, 16 Feb 2002 03:00:00 GMT  
 nodes linked listed and such


Quote:
>I am trying to figure out an exercise that wants me to  delete 3 types of
>nodes, head node, tail node and middle node of a linked list.  It makes no
>sense to me  (newbie)

>the setup is

>typedef struct node
>{
>    int value;                            /* value of node */
>    struct node next;               /* points to next node in list */
>    struct node previous        /* points to previous node in list */
> }NodeRec;

First of all, next and previous are not pointers, but they should be.

Quote:

>typedef  NodeRec *node_ptr;

>The foward pointers follow the node values in sorted order from smallest to
>largest.  The backwards pointer points to each nodes predecessor as
>determined by the sorted ordering

>I need to create a function   test = remove(item,head,tail);

>I've been working on this type of example for days and I must be really
>stupid because I just don't understand it.  I'd appreciate any answers

The best way to tackle this assignment is to write a function that
does the following:

1. Accept the (value of the) node to delete.
2. If you have only the value , Walk through through the list to find
the node
3. If the node has a previous node, let this previous node point to
the next node.
4. If the node has a next node, let this next node point to the
previos node.
5. delete the node.

You have to call this function once for every node you want to delete.

Quote:

>Thanks

>Jim

>--


Bart v Ingen Schenau
--



Sun, 17 Feb 2002 03:00:00 GMT  
 nodes linked listed and such
I hope your's isn't a class assignment...

If you'd like, one of the files included in the software below is
lib/queues.c, which implements doubly-linked lists and the functions you're
looking for as RemoveHead(), RemoveTail(), and RemoveNode().  As you probably
already know, the first two are for implementing LIFO and FIFO respectively,
and the last for simply removing a node regardless of its position in the
queue.  I know the routines work well because I use them frequently.
--
Open Source middleware available at http://pweb.netcom.com/~tgagne
--



Sun, 17 Feb 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. 2 nodes end up in a cycle in a single linked list

2. newbie question: removal of node in linked list

3. How to find a node in link list

4. Realloc()ing data of a node from a linked list

5. why malloc for a new node in linked list

6. Destroying All Nodes in a Linked List

7. Destroying All Nodes is a Linked List

8. Removing node from linked list

9. Removing a NODE for good (double linked lists)

10. deleting a previous node in a singly linked list

11. Question about swapping nodes in a doubly linked list

12. Deleting a node in a linked list

 

 
Powered by phpBB® Forum Software