insert_into_linked_list.c - #include<stdio.h>#include<stdlib.h> typedef struct node1 int data struct node1 link}node int main node*link*ptr*temp*header

insert_into_linked_list.c -...

This preview shows page 1 - 2 out of 2 pages.

#include<stdio.h> #include<stdlib.h> typedef struct node1 { int data; struct node1* link; }node; int main() { node *link,*ptr,*temp,*header; int n,i,choice,insert,key; header=(node *)malloc(sizeof (node)); header->data=0; header->link=NULL; ptr=header; printf("Enter the no.of nodes"); scanf("%d",&n); for(i=0;i<n;i++) { temp=(node*)malloc(sizeof(node)); printf("Enter the data part"); scanf("%d",&temp->data); ptr->link=temp; temp->link=NULL; ptr=ptr->link; } ptr=header->link; printf("The old list is"); while(ptr!=NULL) { printf("The data part is %d\n",ptr->data); ptr=ptr->link; } printf("Choose the corresponding no.s to enter nodes into the list\n 1.At the beginning 2.Anywhere in the list 3.At the end\n"); scanf("%d",&choice); printf("Enter the data part of the node to be inserted\n");
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read both pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture