Tag Archives: Singly Linked List in C

Singly Linked List in C

Data Structure Problems :

Singly Linked List :

Singly linked list has following features .

It contains int data value and next pointer which points to same kind of linked list node.

It is an extensive use of Dynamic Memory Allocation & structure.

 

Structure defined in following way :

struct snode{

int val;

struct snode *next;

};

Declaring a snode variable

struct snode node;

node has following variable to access

val and ptr

A C program on singly linked list.

functions used :

int create_snode(int val,struct snode **node); // To create node

int insert_snode(struct snode **head,struct snode **node );// To insert node

struct snode *find_snode(struct snode **head,int val); // To find node

int delete_snode(struct snode **head,struct snode **node); // To delete node from list

void print_sll(struct snode **head); // To print list

void reverse_sll(struct snode **head); // To reverse list

struct snode* findnthnode(struct snode **head,int lpo);// To find nth node from last in list

 

Code :

/* Singly Linked List Code by Codingstreet.com */

/* Following Features are provided */

/*

Singly Linked List Menu :

[1] Insert Node:

[2] Delete Node:

[3] Print Node:

[4] Reverse List:

[5] Find Nth node from Last :

[6] Exit:

*/