Tuesday, January 30, 2024

Generalised Linked Lists - DSTC using C Language (Source Code Implemented)

Generalised Linked Lists

Implemented using C Language
 

C Language Code:

              GLIST.CPP         

// Generalized Linked Lists...

#include<stdio.h>
#include<conio.h>
#include<alloc.h>

typedef struct s
{
int type;
union u
{
int iinfo;
float finfo ;
char sinfo[20] ;
}uu ;
struct s *next ;
}node ;


typedef struct s1
{
node *first;
}glist;


node* createnode()
{
float p ;

node *n;
char flval[20] ;
n=(node*)malloc(sizeof(node)) ;
printf("\n Enter the type of value to input 1-int 2-float 3-string");
scanf("%d",&n->type) ;


fflush(stdin) ;
switch(n->type)
{
case 1:
printf("\n Enter the int value") ;
scanf("%d",&n->uu.iinfo) ;
//printf("\n %d",n->uu.iinfo);
break;
case 2:
printf("\n Enter the float value") ;
float ab ;
scanf("%f", &n->uu.finfo) ;
n->uu.finfo = ab ;
// printf("\n %f",n->uu.finfo) ;
break;
case 3:
printf("\n Enter the string value") ;
scanf("%s",n->uu.sinfo) ;
//printf("\n %s",n->uu.sinfo) ;
break;
}
n->next=NULL;
return n;
}

glist* createlist(void)
{
glist* g;
g=(glist*)malloc(sizeof(glist));
g->first=NULL;
return g;
}

No comments: