Struct for previous and next
Code:
struct tnode node{
int nim;
tnode *next,*prev;
}*head,*tail,*curr;
Before learning the other type of Linked List we must understand how to Insert,Delete,Push,Pop the Data in the List.
Linked List: Insertion
Code:
struct tnode *node =
(struct tnode*) malloc (sizeof(struct tnode));
node->value = x;
node->next = head;
head = node;
Code:
struct tnode *curr = head;
if ( head->value == x ) {
head = head->next;
free(curr);
}
Linked List: Push
Code:
void Push();
struct tnode *node = (struct *node) malloc(sizeof(struct node));
if(head==NULL){
head = nim;
}else{
head->next=nim;
}
void PopHead();
//set global variable *temp;
struct tnode *node = (struct *node) malloc(sizeof(struct node));
temp = head;
head=temp->next;
free(temp);
Double Linked List
In Double Linked List, every node has a pointer to it's previous and next node.
References: BinusMaya

No comments:
Post a Comment