Link lists..



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;

}

}


.



Relevant Pages

  • Re: Dinamically allocate array of array of structures
    ... Age: 32 ... Initials: B.L. ... struct list_node *next; ... list_type *head; ...
    (comp.lang.c)
  • Re: PR-Tree
    ... //structure used to store the head and the tail of the loaded ... typedef struct matrix { ... int points; ...
    (comp.lang.c)
  • Re: C++ in the kernel
    ... private struct foo { ... for instance to cache a function pointer for lazy binding ... list_insert_before(elem, elem {,head ?}) ...
    (freebsd-arch)
  • Re: how to copy strings into a linked list?
    ... I'm trying to write code that gets fixed-length strings from the user ... struct list_node *next; ... struct list_node *tail, ... list_fprint(stdout, head); ...
    (comp.lang.c)
  • Re: structs help
    ... >The struct is declared in anouther header file like this... ... head has type struct ln** or pointer to pointer to struct ln. ... Functions that manipulate linked lists usually use the return type to ...
    (comp.lang.c)