0% found this document useful (0 votes)
9 views2 pages

Singly Linklist

Uploaded by

stdesai1005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Singly Linklist

Uploaded by

stdesai1005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Aim: Singly linklist

#include <stdio.h>

#include <stdlib.h>

// Define the node structure

struct Node {

int data;

struct Node* next;

};

// Function to insert a node at the beginning

void insertStart(struct Node** head, int data) {

struct Node* newNode = (struct Node*) malloc(sizeof(struct Node));

newNode->data = data;

newNode->next = *head;

*head = newNode;

printf("Inserted %d\n", newNode->data);

// Function to delete a node from the beginning

void deleteStart(struct Node** head) {

if (*head == NULL) {

printf("Impossible to delete from empty Singly Linked List\n");

return;

struct Node* temp = *head;

*head = (*head)->next;
printf("Deleted: %d\n", temp->data);

free(temp);

// Function to display the linked list

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;

insertStart(&head, 10);

insertStart(&head, 20);

insertStart(&head, 30);

display(head);

deleteStart(&head);

display(head);

return 0;

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