Linked List -part 2

      LINKED LIST

Definition:

A Linked list is a sequence of items(objects) where every item is linked to the next.

->Each node stores

-element

-link   to  the next node.

Graphical    structure:

7

Eg:

8

 

NOTE:

  • Linked list last node pointer should be null always.
  • payload/elements/Data can be anything like city name,number,characters,etc.
  • For complex structures use linked list.

 

 

 

Example for payload/elements/data:                      

5

 

 

 

  • Simply don’t use linked list for storing a number,because it will take 4 bytes for memory which is waste of memory.

 

  • Use linked list for complex structures like,

             struct list

{

char name[MAXLEN];

char address[MAXLEN];

char phone[MAXLEN];

struct list *next;

}ADDRESS;

NEXT WE WILL SEE HOW TO CREATE A NEW NODE IN LINKED LIST:

 

  • Allocate space for a new node.
  • Set the next pointer to the value of NULL.
  • Set the  data value for  the node.

 

SIMPLE  CODING: 

ADDRESS   *new_name;

new_name=(ADDRESS*)malloc(sizeof(ADDRESS));

gets(new_name->name);

gets(new_name->address);

new_name->next=NULL;

POINT TO REMEMBER IN LINKED LIST WHILE CODING:

  • Pointer setting.
  • Memory allocation.
  • Data setting.
  • Value setting.
  • Null setting.

THIS IS THE WORK FOR YOU:

  • Declare a student structure and create an object then print the values.
  • Do the same with structure pointer.

—–PRIYANKA LOG          

For more innovative vidoes follow us on ” http://www.guvi.in “:)  

6

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s