0% found this document useful (0 votes)
8 views

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)
8 views

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