Thread: Iterating through a linked list

  1. #1
    Registered User
    Join Date
    Apr 2009

    Iterating through a linked list

    Hey C forum, can someone give me ideas/ psuedocode for iteration through a linked list?
    I'm passing in my super-struct epg which is like this:
    struct epg {
    	DateTime epoch;        /* The time stamp from the XML file */
    	Channel* channelList;  /* Head of a linked list of channel structs */
    Then I want to run through this whole epg struct, printing to stdout. I have two sub-structs running off epg:
    struct channel {
    	char *id;				/* Channel id  */
    	char *name;				/* Channel name */
    	Programme* progList;	/* Head of a linked list of programmes */
    	Programme* lastProg;	/* Pointer to the last program in the list */
    	Channel* next;			/* Link to the next channel in the channel list */
    struct programme {
    	DateTime start;			/* Start time for the programme */
    	DateTime stop;			/* Stop time for the programme */
    	char* title;			/* Programme title */
    	char* description;		/* Programme description or NULL if no description given */
    	char* rating;			/* Rating e.g. "PG". NULL if no rating available */
    	Programme* next;		/* Link to next programme in a list */
    I just can't visualize how to iterate through the linked lists, especially how to move to the sub-structs and back

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    On me hyperplane
    Why not start with one list at a time?

    I'm guessing channel list should point to the head node of the channel structs on its associated list.

    First you need t o write a funtion to insert nodes to your list. The simplest way to do this is to have the new node become the head and have its 'next' pointer set to the previous head node.

    Also, dont forget to set your initial head node to NULL. as this tells you where to stop when iterating over the list.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 10:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM