Wisdom Materials
Home
About Us
Our Clients
Careers
Services
Education
Jobs
News
Business
Health
Astrology
Entertainment
RealEstate
Devotion
Contact Us
Data Structures using C Language
/ Singly Linked List Implementation using C program
Program
Copy text
#include
#include
struct Node { int data; struct Node *next; }; void deletenode (struct Node **head) { struct Node *temp = *head; if (*head == NULL) { printf ("Linked List Empty, nothing to delete"); return; } *head = (*head)->next; printf ("\n%d deleted\n", temp->data); free (temp); } void insertnode (struct Node **head, int data) { struct Node *newNode = (struct Node *) malloc (sizeof (struct Node)); newNode->data = data; newNode->next = *head; *head = newNode; printf ("\n%d Inserted\n", newNode->data); } void display (struct Node *node) { printf ("\nLinked List: "); while (node != NULL) { printf ("%d ", node->data); node = node->next; } printf ("\n"); } int main () { struct Node *head = NULL; insertnode (&head, 9); insertnode (&head, 8); insertnode (&head, 7); insertnode (&head, 6); insertnode (&head, 5); display (head); deletenode (&head); deletenode (&head); display (head); return 0; }
Output
Linked List : 5 6 7 8 9 5 deleted 6 deleted Linked List : 7 8 9
Home
Back