What is the Linked List Program in C Example

  • Post author:
  • Post category:C

What is the Linked List Program in C

What is the Linked List? What is the Linked List Program in C In the C programming Language linked list is a sequence of DS (data structures), which are connected with each other via the links. A linked list is a sequence of links that contain items. Each link contains a connection to another link. the Linked list is the second most-used data structure after array.

Thank you for reading this post, don't forget to subscribe!

Linked List Program in C

#include <stdio.h>

struct linkList

{

int data;

struct linkList* nextNode;

};

int main()

{

struct linkList firstNode, secondNode, thirdNode, head;

firstNode.data=10;

secondNode.data=20;

firstNode.nextNode=&secondNode;

thirdNode.data=30;

secondNode.nextNode=&thirdNode;

thirdNode.nextNode=NULL;

head.nextNode=&firstNode;

while(head.nextNode!=NULL){

printf("Data= %d ",head.nextNode->data);

head.nextNode=head.nextNode->nextNode;

}

return 0;

}

Linked list Insertion

Recursive function program In the C (clikhere)

[toggle title=”Try this too”]
#include <stdio.h>

struct linkList

{

int data;

struct linkList* nextNode;

};

int main()

{

struct linkList firstNode, secondNode, thirdNode, *head;

firstNode.data=10;

secondNode.data=20;

firstNode.nextNode=&secondNode;

thirdNode.data=30;

secondNode.nextNode=&thirdNode;

thirdNode.nextNode=NULL;

head=&firstNode;

while(head!=NULL){

printf("Data= %d ",head->data);

head=head->nextNode;

}

return 0;

}
[/toggle]
OUTPUT

Data= 10

Data= 20

Data= 30

  • Check this same code with *head, and try to understand the difference
    And think of pointers concepts.
  • Pointer can have the address of a variable of the same type as the pointer variable
    when the pointer type is a struct type, then if you want to access the members of struct then you have to use -> symbol.

Linked list in Datastructer

firstNode, secondNode, thirdNode are normal variables of structlinkList
  • but *head is a pointer variable
[alert-success]

int a,b,c, *e;

Where a, b, c are int variables but e is a pointer variable that can point to another int.[/alert-success]

e=&a;
suppose a=10;
print (“%d”,*e) ; // it will print the value pointed by ‘ e ‘
Which is the address of a and it will print 10;

[alert-warning]first.nextNode is pointing to second, and second.NextNode pointing to third[/alert-warning]

Now the head is pointing to the first node, which means it has access to firstNode’s data and nextNode.

Linked List in C

What is the Linked List Program in C
What is the Linked List Program in C
head=&firstNode;

while(head!=NULL){
printf("Data= %d ",head->data);
head=head->nextNode;
}

loop until head not getting NULL,
initially head has firstNode, it will print its data, then we say

head=head->next;

Means head will point to nextnode ” which is the secondnode ” then it will move to the thirdnode.

END

Saurabh Nissa

This is SaurabhNissa, Owner of Thesmolt.com I'm Graduated from Magadh University in 2019 with 75%. Currently, I'm working on my Personal educational website for teaching Programming language free of Coast, and want to provide a Full setup for Specially BCA student