How to declare a structure of a linked list?

October 28, 2007 · Filed Under Linked List, Placement Questions 



Don't want to miss a single bit? Subscribe By Email for Daily Jobs

Enter your email address :

All the latest from JobsAdda on Jobsadda.com delivered to your mailbox everyday.

Home
How to declare a structure of a linked list?

The right way of declaring a structure for a linked list in a C program is

struct node {
int value;
struct node *next;
};
typedef struct node *mynode;

Note that the following are not correct

typedef struct {
int value;
mynode next;
} *mynode;

The typedef is not defined at the point where the “next” field is declared.

struct node {
int value;
struct node next;
};
typedef struct node mynode;

You can only have pointer to structures, not the structure itself as its recursive!

Bookmark/Search this post with:
delicious delicious | digg digg | reddit reddit | magnoliacom magnoliacom | google google | yahoo yahoo | technorati technorati
» email this page
Post new comment
Subject:
Math Question: What is 6 + 8?: *
Please solve the math problem above and type in the result. e.g. for 1+1, type 2
Comment: *
Input format
Filtered HTML

* Allowed HTML tags: