top of page

Linked List Insertion At End

Writer's picture: Code CrazeCode Craze


#include <stdio.h>

struct node{

int data;

struct node *next;

};


struct node *head,*newnode;

int choice;


void main() {

printf("\n----Insertion At End----");

struct node *temp;

do

{

newnode = (struct node *)malloc(sizeof(struct node));

printf("\nEnter data : ");

scanf("%d", &newnode->data);

newnode->next=0;

if(head==0)

{

head=temp=newnode;

}

else{

temp=head;

while(temp->next!=0)

{

temp=temp->next;

}

temp->next=newnode;

}

printf("\nEnter your choice : (0/1) ");

scanf("%d", &choice);

}while(choice);

temp=head;

printf("\n");

while(temp!=0)

{

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

temp=temp->next;

}

}

0 views0 comments

Recent Posts

See All

Stack Using Queue

A stack can be implemented using two queues in C. The basic idea is to use one queue for enqueue operations and another for dequeue...

Comments


bottom of page