0% found this document useful (0 votes)
57 views3 pages

Delete First

The document describes a C program to delete the first node in a linked list. It includes functions to insert nodes at the end of the list, delete the first node, and display the list. The main function uses a do-while loop to display a menu and call the appropriate functions based on user input.

Uploaded by

satya_saraswat_1
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views3 pages

Delete First

The document describes a C program to delete the first node in a linked list. It includes functions to insert nodes at the end of the list, delete the first node, and display the list. The main function uses a do-while loop to display a menu and call the appropriate functions based on user input.

Uploaded by

satya_saraswat_1
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

www.eazynotes.

com

Gursharan Singh Tatla

Page No. 1

DELETE FIRST
/**** Program to Delete First Node in a Linked List ****/

#include <stdio.h> void insert_last(); void delete_first(); void display(); struct node { int info; struct node *link; } *start=NULL; int item; main() { int ch; do { printf("\n\n\n1. Insert Last\n2. Delete First\n3. Display\n4. Exit\n"); printf("\nEnter your choice: "); scanf("%d", &ch); switch(ch) { case 1: insert_last(); break; case 2: delete_first(); break; case 3: display(); break;

case 4: exit(0);

www.eazynotes.com

Gursharan Singh Tatla

Page No. 2

default: printf("\n\nInvalid choice: Please try again.\n"); } } while (1); } void insert_last() { struct node *ptr; printf("\n\nEnter item: "); scanf("%d", &item); if(start == NULL) { start = (struct node *)malloc(sizeof(struct node)); start->info = item; start->link = NULL; } else { ptr = start; while (ptr->link != NULL) ptr = ptr->link; ptr->link = (struct node *)malloc(sizeof(struct node)); ptr = ptr->link; ptr->info = item; ptr->link = NULL; } printf("\nItem inserted: %d\n", item); } void delete_first() { struct node *ptr; if (start == NULL) printf("\n\nLinked list is empty.\n"); else { ptr = start; item = start->info; start = start->link; free(ptr);

www.eazynotes.com

Gursharan Singh Tatla

Page No. 3

printf("\n\nItem deleted: %d", item); } } void display() { struct node *ptr = start; int i=1; if (ptr == NULL) printf("\nLinklist is empty.\n"); else { printf("\nSr. No.\t\tAddress\t\tInfo\t\tLink\n"); while(ptr != NULL) { printf("\n%d.\t\t%d\t\t%d\t\t%d\n", i, ptr, ptr->info, ptr->link); ptr = ptr->link; i++; } } }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy