adding nodex

This is a discussion on adding nodex within the C++ Programming forums, part of the General Programming Boards category; Hi, Can anyone help me with this problem. I am going to store a graph in a linked adjacency list, ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    29

    Question adding nodex

    Hi,
    Can anyone help me with this problem.
    I am going to store a graph in a linked adjacency list, (cities and distance between them) and I am taking in the city input first. I am having trouble moving on to the next vertexnode(incrementing) to add the cities to the linked list. I can see this because I only get the last one I entered to display.

    My structure looks like this:


    struct arcnode{
    char vertex[10];
    int weight;
    struct arcnode *nextarc;
    };

    struct vertexnode{
    char city[10];
    struct vertexnode *nextvertex;
    struct arcnode *nextarc;
    };

    Anyone any ideas, much appreciated.
    Thanks
    Colin

  2. #2
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Don't you have any functions that act on these structures? Without them, nobody will be able to help you (unless they write them for you, which is BAD BAD BAD )

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    29

    Talking

    Shame on you Biosx, tut tut, he who has little faith!!!
    Thanks but I figured out my error after I posted my problem.
    Thanks anyway,
    Colin


    /*This function inserts a vertex node into an Linked */
    /* Adjacency List */
    void insert_vertex(struct vertexnode **list)
    {

    while ( (*list)->nextvertex) /* Get to end of vertex list */
    *list = (*list)->nextvertex;

    (*list)->nextvertex = new(struct vertexnode);
    *list = (*list)->nextvertex;

    clrscr();
    printf ("\t\t New City (Vertex)\n");
    printf ("\t\t-------------------\n\n");
    printf ("Please enter a name for the city: "); /* Input City name */
    scanf ("%s", (*list)->city);
    printf ("\n\nConfirmation of city name: %s\n", (*list)->city);
    getche();
    }

  4. #4
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Oh I had faith in you. I just wanted you to post your functions :-D

    Glad to hear you figured it out. You know, I notice that if I ever get stuck, I usually find the problem by just getting ready to post the code

    BTW: Next time, use the [ code ] tags

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. adding matrices, help with switches
    By quiet_forever in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2007, 08:21 AM
  2. Adding nodes to a linked list
    By bluescreen in forum C Programming
    Replies: 4
    Last Post: 11-09-2006, 12:59 AM
  3. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 02:44 PM
  4. Java: Sorting and Adding a Row in Table
    By alphaoide in forum Tech Board
    Replies: 4
    Last Post: 08-12-2005, 08:22 PM
  5. Adding and subtracting time?
    By JCCC in forum C Programming
    Replies: 3
    Last Post: 03-29-2002, 01:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21