Documente Academic
Documente Profesional
Documente Cultură
1
OUTLINES
Introduction
Differences between Link List and
Array
Link List Declaration
Basic Link List Operation
Circular Link List
Double Link List
Exercises
2
Differences betweenLink List Basic Link Circular
ntroduction Double Link List
Exercises
Link List and Array
Declaration
List Operation
Link List
LINK LIST
Link List is an ordered collection of elements called
nodes which has two parts.
The nodes connect by pointer.
3
Differences betweenLink List Basic Link Circular
ntroduction Double Link List
Exercises
Link List and Array
Declaration
List Operation
Link List
struct STUDNODE
{ char ID [4];
char name [20];
float CGPA;
STUDNODE * Next;
};
5
Differences betweenLink List Basic Link Circular
ntroduction Double Link List
Exercises
LINK LIST EXTERNAL
Link List and Array
Declaration
List Operation
Link List
POINTER
External pointers are needed in a link list for the
following purposes:
1) Pointer to hold the list by pointing to the first
node in list. (usually declared as Head, First,
Front, Hptr and etc)
2) Pointer to traverse/ visit the nodes in list.
(usually declared as Current, Curr, CPtr,
Currptr and etc)
3) Pointer to hold new node. (usually declared as
NewPtr, Nptr and etc)
4) Pointer to mark the location of the node to be
declared or inserted. (usually declared as
Temp, Tempptr and etc)
6
Differences betweenLink List Basic Link Circular
ntroduction Double Link List
Exercises
LINK LIST EXTERNAL
Link List and Array
Declaration
List Operation
Link List
Syntax:
POINTER
Nodename *pointer1,*pointer2,..,*pointerN;
Example 1:
struct Node
{ int Data; //to store integer value
Node *Next; //a pointer to next node
};
Node *Head, *Current, *NewNode;
Example 2:
struct STUDNODE
{ char ID [4];
char Name [20];
float CGPA;
STUDNODE * Next;
};
STUDNODE *Firstptr, *CurrPtr, *NewPtr; 7
Differences betweenLink List Basic Link Circular
ntroduction Double Link List
Exercises
Link List and Array
Declaration
List Operation
Link List
8
Differences betweenLink List Basic Link Circular
ntroduction Double Link List
Exercises
Link List and Array
Declaration
List Operation
Link List
10
Differences betweenLink List Basic Link Circular
ntroduction Double Link List
Exercises
Link List and Array
Declaration
List Operation
Link List
sum = 0;
count = 0;
current = head; // point the first node in the list
while (current != NULL)
{ sum sum+current->data; // sum node
count++; // count the node
current = current->Next; // move to next node
}
average = sum/count; // calculate average
15
Nptr
Nptr 12