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

Singly linked list program

Copyright
© © All Rights Reserved
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)
6 views

Singly linked list program

Copyright
© © All Rights Reserved
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

singly linked list

#include<stdlib.h>

#include<stdio.h>

struct Node

{ int data;

struct Node *next;

void deleteStart(struct Node** head)

struct Node* temp = *head;

if(*head == NULL)

{ printf("lmpossible to delete from


empty Singly Linked List");

return;

*head = (*head)->next;

printf("Deleted:%d\n",temp->data);
free(temp);

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("lnserted%d\n",newNode->data);

void display(struct Node* node)


{
printf("\nLinked List: I');
while(node!=NULL)
{

printf("%d ",node->data);

node = node->next;

printf("\n");

int main()

struct Node* head = NULL;

insertStart(&head, 1 00);

insertStart(&head,80);

insertStart(&head,60);

insertStart(&head,40);

insertStart(&head,20);

display(head);

deleteStart(&head);
deleteStart(&head);
display(head);

return 0;

OUTPUT

Inserted 100

Inserted 80

Inserted 60

Inserted 40

Inserted 20
Linked list:20 40 60
80 100

Deleted:20

Deleted:40

Linked list:60 80
100

You might also like