//there is a simple program that will create a linked list.
//language=C

#include<stdio.h>
#include<stdlib.h>

struct linked_lists{
         int data;
         struct linked_lists *next;
};


typedef struct linked_lists node;
//this will change the name to node

void create(node *p);
//list will be created using this function

int main(){

         node *head;
//because linked_lists is a dynamic data structure,its nodes should be declared dynamically
         head=(node*)malloc(sizeof(node));
         create(head);
         //calls the function
         return 0;
}

//function definition of create function 
 
void create(node *p){

 //input will terminate when enter is pressed and input can be continued by pressing space

       char c;
       scanf("%d%c", & p->data ,& c);

       if(c=='\n'){
             p->next=NULL;
       }
       else{
             p->next=(node*)malloc(sizeof(node));
             //recursion occurs
             create(p->next);
       }
       return;
}
                  



No comments:

Post a Comment

Kruskal Algorithm

Minimum Cost Spanning Tree By Kruskal Algorithm using priority_queue in c++ #include<bits/stdc++.h> using namespace std; typedef p...