

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


#include <stdio.h> #include <stdlib.h> struct node { int data; struct node next; }head,new,tail,*temp; void createList(int n) { int i,value; head = (struct node *)malloc(sizeof(struct node)); printf("enter the data 1: "); scanf("%d",&value); head->data = value; head->next =NULL; tail = head; for(i=2;i<=n;i++) { new = (struct node *)malloc(sizeof(struct node)); printf("\n"); printf("Enter the data of node %d: ", i); scanf("%d", &value); new->data = value; new ->next = NULL; tail->next = new;
tail = new; } } void display() { temp = head; while(temp!=NULL) { printf("\n %d",temp->data); temp = temp->next; } } int main() { int n; printf("--linked list--\n"); printf("Enter the number of items in the list: "); scanf("%d",&n); createList(n); display(); }