You are on page 1of 4

ITI101-Fundamental of computing

Lecture 23
07-11-12

Link list and structures


Step_1: structure of node is defined (data variables to values and

pointer to store address of next node)


Step_2: dynamically generated new nodes (assign values and store
address in previous node pointer)
Two pointers are needed, pointer head (fixed pointer)to stores
staring address and second pointer current (moving pointer)
which points to new or node on which we are working.
head

Node 1

current

Node 2

Node 3

Node 4

Link list and structures


Step_1: structure of node is defined (data variables to values and

pointer to store address of next node)


Step_2: dynamically generated new nodes (assign values and store
address in previous node pointer)
Two pointers are needed, pointer head (fixed pointer)to stores
staring address and second pointer current (moving pointer)
which points to new or node on which we are working.
head

Node 1

current

Node 2

Node 3

Node 4

Link list basic implementation


struct node
{ int x;
struct node *next;
};
typedef struct node node;
node *head, *curr;
head=(node *)malloc(sizeof (node));
curr=head;
do{
Scanf(%d,&curr->x);
curr=(node *)malloc(sizeof(node));
curr=curr->next;

Printf(press Y to continue ---press N to stop);


Scanf(%c, &choice);
}while(choice==Y)

Integer X to store data, pointer


nextof struct node data type

head and curr pointer having


address of first node created with
malloc
Arrow operator (->)is used to
access the variables of structure
through the pointers.

Create new node and move curr


pointer to new node (curr->next)

You might also like