Tuesday, March 3, 2020

Linked List II

According to the material that has been passed on to me about Linked List. Here's what i can conclude from the materials:

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;

Linked List: Delete


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);

After learning how to Insert,Delete,Push,and Pop, we can now proceed to the other type of Linked List.

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