Docsity

linked list c programming, High school final essays of Computer science

Toggle sidebar
bg1
#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;
pf2

Partial preview of the text

Download linked list c programming and more High school final essays Computer science in PDF only on Docsity!

#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(); }