Link lists..
- From: johnnash <johnnash86@xxxxxxxxx>
- Date: Fri, 29 Feb 2008 02:36:49 -0800 (PST)
i'm declaring a data structure for link list of integers in A.h
#ifndef A_H (can anyone please explain how ifndef works as well..i
just seem to see it in almost every program)
#define A_H
typedef struct node nodestruct
{
int data;
struct node *next;
}node;
extern node * head /*indicates head node of the list , declaring as
extern so that it can be used in A.c */
Now i want to use this link list so..A.c
#include "A.h"
node * head; /*definition, is this sufficient for link list ?, can i
initialize head to NULL here itself */
LL()/* computes the link list */
{
node *p, *prev; /*prev is previous node */
head = NULL;
head->next = NULL;
for(i=0;i<10;i++) /*Creating list of 10 elements */
{
p = (node *) malloc(sizeof(node));
p->next = NULL;
scanf("%d",&(p->data));
if(head ==NULL)
head = p;
else
{
prev->next = p;
prev = p;
}
}
main()
{
struct node *p;
LL();
p = head;
while(p!= NULL)
{
printf("%d\n",p->data);
p = p->next;
}
}
.
- Follow-Ups:
- Re: Link lists..
- From: Joachim Schmitz
- Re: Link lists..
- From: Joachim Schmitz
- Re: Link lists..
- From: Mark Bluemel
- Re: Link lists..
- Prev by Date: Re: Is there stack associated when a executing an inline function?
- Next by Date: Re: Freeing memory - will it be available immediately
- Previous by thread: Is there stack associated when a executing an inline function?
- Next by thread: Re: Link lists..
- Index(es):
Relevant Pages
|