data structure for graph

Discussion in 'C Programming' started by Sameer, Sep 15, 2003.

  1. Sameer

    Sameer Guest

    Hello,

    A data structure for the implementation of graph can be

    struct node
    {
    int index;
    struct node *next;
    };

    struct adjnode // node adjacent to node
    {
    int adjindex;
    struct node *next;
    struct adjnode *next;
    };


    input file is

    node1 adjnode1 adjnode3
    node2 adjnode1 adjnode4
    node3 adjnode1 adjnode4
    node3 adjnode2 adjnode3

    such that 1234 forms a quadrilateral.

    How can I populate all the data in one file read...


    Kindly reply,
    Regards,
    Sameer.
     
    Sameer, Sep 15, 2003
    #1
    1. Advertising

  2. Sameer

    Sameer Guest

    "Sameer" <> wrote in message
    news:bk49r7$oln04$-berlin.de...
    > Hello,
    >
    > A data structure for the implementation of graph can be
    >
    > struct node
    > {
    > int index;
    > struct node *next;
    > };
    >
    > struct adjnode // node adjacent to node
    > {
    > int adjindex;
    > struct node *next;
    > struct adjnode *next;
    > };
    >
    >
    > input file is
    >
    > node1 adjnode1 adjnode3
    > node2 adjnode1 adjnode4
    > node3 adjnode1 adjnode4
    > node3 adjnode2 adjnode3
    >
    > such that 1234 forms a quadrilateral.
    >
    > How can I populate all the data in one file read...
    >
    >
    > Kindly reply,
    > Regards,
    > Sameer.
    >
    >

    sorry the currect input file is

    node1 adjnode2 adjnode3
    node2 adjnode1 adjnode4
    node3 adjnode1 adjnode4
    node4 adjnode2 adjnode3
     
    Sameer, Sep 15, 2003
    #2
    1. Advertising

  3. Hi Sameer,
    "Sameer" <> wrote in message
    news:bk49us$nsql6$-berlin.de...
    ....
    | > A data structure for the implementation of graph can be
    | >
    | > struct node
    | > {
    | > int index;
    | > struct node *next;
    | > };
    | >
    | > struct adjnode // node adjacent to node
    | > {
    | > int adjindex;
    | > struct node *next;
    | > struct adjnode *next;
    | > };
    ....
    | sorry the currect input file is
    |
    | node1 adjnode2 adjnode3
    | node2 adjnode1 adjnode4
    | node3 adjnode1 adjnode4
    | node4 adjnode2 adjnode3

    Unfortunately, your question remains too vague.
    There are many kinds of graphs (cyclic/acyclic,
    oriented or not, ...), and even more ways
    to represent them using different data structures.

    From your post, I still do not understand how
    struct node and struct adjnode are intended to
    be used.

    I think you need to tell more about your
    goals/constraints/requirements.


    Regards,
    Ivan
    --
    http://ivan.vecerina.com
     
    Ivan Vecerina, Sep 15, 2003
    #3
  4. Sameer

    Malcolm Guest

    "Sameer" <> wrote in message

    > A data structure for the implementation of graph can be
    >
    > struct node
    > {
    > int index;
    > struct node *next;
    > };
    >
    > struct adjnode // node adjacent to node
    > {
    > int adjindex;
    > struct node *next;
    > struct adjnode *next;
    > };
    >
    >
    > input file is
    >
    > node1 adjnode1 adjnode3
    > node2 adjnode1 adjnode4
    > node3 adjnode1 adjnode4
    > node3 adjnode2 adjnode3
    >
    > such that 1234 forms a quadrilateral.
    >
    > How can I populate all the data in one file read...
    >

    If you're only allowed to make one call to a read function, the only thing
    you can do is read to a temporary buffer. This doesn't really answer ypur
    question.

    It looks like each line starts with a terminal node, then contains an
    arbitrary number of adjnodes that point to the terminal node, and to another
    adjnode.
    However what I don't understand is that you seem to have declared 8
    adjnodes, yet the maximum index is four. Are you sure that adjnodes don't
    actually contain two adjnode pointers?
     
    Malcolm, Sep 15, 2003
    #4
  5. On Mon, 15 Sep 2003 17:36:50 +0530, "Sameer" <>
    wrote:

    >Hello,
    >
    >A data structure for the implementation of graph can be
    >
    >struct node
    >{
    > int index;
    > struct node *next;
    >};
    >
    >struct adjnode // node adjacent to node
    >{
    > int adjindex;
    > struct node *next;
    > struct adjnode *next;
    >};


    There can be only one member named next is struct adjnode. Perhaps
    you would like to call these two pointer n_next and a_next.



    <<Remove the del for email>>
     
    Barry Schwarz, Sep 16, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Sakkis
    Replies:
    1
    Views:
    462
    Szabolcs Nagy
    Jan 29, 2007
  2. Dr Ann Huxtable

    Missing Graph.h and (Graph.lib) woes - any help

    Dr Ann Huxtable, Dec 21, 2004, in forum: C Programming
    Replies:
    6
    Views:
    656
    Dr Ann Huxtable
    Dec 21, 2004
  3. Jef Driesen
    Replies:
    3
    Views:
    2,557
    mlimber
    Jan 24, 2006
  4. Almoni
    Replies:
    0
    Views:
    3,106
    Almoni
    Jan 17, 2010
  5. Emilio Mayorga
    Replies:
    6
    Views:
    344
    Martien Verbruggen
    Oct 8, 2003
Loading...

Share This Page