generic linked list

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sengupta_arka123@yahoo.co.in

    generic linked list

    How do I implement a generic linked list?
  • Malcolm McLean

    #2
    Re: generic linked list


    <sengupta_arka1 23@yahoo.co.inw rote in message
    news:83e5b7a5-a7d1-4bbd-9987-0f9da6935ea8@x3 0g2000hsd.googl egroups.com...
    How do I implement a generic linked list?
    typedef struct node
    {
    struct node *prev;
    struct node *next;
    void *data;
    } NODE;

    typedef struct
    {
    struct node *first;
    struct node *last;
    } LINKEDLIST;


    --
    Free games and programming goodies.


    Comment

    • Eric Sosman

      #3
      Re: generic linked list

      sengupta_arka12 3@yahoo.co.in wrote:
      How do I implement a generic linked list?
      What do you mean by "generic?"

      --
      Eric.Sosman@sun .com

      Comment

      • Michael Mair

        #4
        Re: generic linked list

        sengupta_arka12 3@yahoo.co.in wrote:
        How do I implement a generic linked list?
        Depends.
        The usual way is to have a struct containing
        the list infrastructure and a pointer to the data
        and provide ways for the user to affect the data,
        e.g. via function pointers.

        With
        struct GenSLList {
        struct GenSLList *pNext;
        void *pData;
        };
        you can perform some operations purely on the linked list,
        like inserting new nodes
        struct GenSLList *pNode1, *pNode2;
        ....
        pNode1->pNext = pNode2;
        whereas things like creating new nodes, deleting nodes, sorting
        the list etc. need your input:
        struct GenSLList*
        CreateSllNode (int (*CreateDataFro m)(void**, void*),
        void *pTemplateData) ;
        which provides a new list node and, depending on the CreateDataFrom
        and pTemplateData parameters, may do things to also provide
        new data or set the pData member to pTemplateData or ...

        Note that general programming / algorithm / data structure questions
        may be better asked in comp.programmin g. As soon as you have written
        some C code and have specific questions regarding that code, you can
        ask here.


        Cheers
        Michael
        --
        E-Mail: Mine is an /at/ gmx /dot/ de address.

        Comment

        • Ravishankar S

          #5
          Re: generic linked list

          <sengupta_arka1 23@yahoo.co.inw rote in message
          news:83e5b7a5-a7d1-4bbd-9987-0f9da6935ea8@x3 0g2000hsd.googl egroups.com...
          How do I implement a generic linked list?
          Use the list.h set of interfaces from the linux kernerl sources


          Comment

          Working...