Program to traverse the linked list

August 29th, 2009  | Published in Amit Sahrawat, Data Structures, Linux Sample Programs








/* Structure for a linked list*/
struct list{
    int num;
    struct list* next; /* pointer to next node in list*/
};

/* Function to traverse the linked list given the starting node pointer */
void traverse(struct list* node)
{
    printf(“[%s]\n”,__FUNCTION__);
    while(node != NULL)
    {
        printf(“%d–>”,node->num);
        node = node->next;
    }
    printf(“NULL\n”);
}

/* Function to use the linked list functions*/
int main()
{
    struct list* node = NULL;
    struct list* new = NULL;
    int i;

    for(i=0; i < 10; i++)
    {
        insert(&node,i);
    }
    traverse(node);
}

Subscribe

Get articles in your inbox.

Enter your email address:

Join Us

Twitter Chatter


Special Recent Posts

Withdraw Cash from ATM without Card

Withdraw Cash from ATM without Card

September 17th, 2011

Now, there is no need to carry Automated Teller Machine (ATM) card with withdraw cash. Cash-On-Mobi[...]

Health Care For Diabetes

Health Care For Diabetes

September 3rd, 2011

Symptoms to watch out for: If you feel anxious, tired, confused, unusually hungry, or a fast heart b[...]

How To Take Proper Care of Knees

How To Take Proper Care of Knees

August 31st, 2011

Recognize the problem: Firstly, recognize whether it is just a common ache or something more serious[...]

Recommendations

Archives

Categories