#include <stdio.h>
#include <stdlib.h>
#include<time.h>
struct SLnode{//the slave link
int key;
struct SLnode *next;
};
typedef struct SLnode *SLnodePtr;
struct HBnode{//the master link
int key;
struct HBnode *next;
SLnodePtr bottom;
};
typedef struct HBnode *HBnodePtr;
HBnodePtr HB=NULL;
HBnodePtr createHBlist(int n, int m);
SLnodePtr createSLlist(int n);
SLnodePtr flattenList(const HBnodePtr L);
void printHBlist (const HBnodePtr L );
int main(){
createHBlist(5,7);//master links and slave links' length
printf("\nDone\n");
printHBlist(HB);
}
SLnodePtr createSLlist(int n){
n=rand()%(n);
int i,r;
SLnodePtr SL=NULL;
for(i=0;i<n;i++){
SLnodePtr newNode;
newNode=malloc(sizeof(SLnodePtr));
if (newNode == NULL) {
printf("Error: malloc failed in add_to_list\n");
exit(EXIT_FAILURE);}
r=rand()%101;
printf("%d ",r);
newNode->key=r;
newNode->next=SL;
SL=newNode;
}
return SL;
}
HBnodePtr createHBlist(int n, int m){
int i,r;
srand((int)time(NULL));
for(i=0;i<n;i++){
SLnodePtr SL=NULL;
HBnodePtr newNode;
newNode=malloc(sizeof(HBnodePtr));
if (newNode == NULL){
printf("Error: malloc failed in add_to_list\n");
exit(EXIT_FAILURE);}
r=rand()%101;
newNode->key=r;
printf("\n%d link with :",r);
newNode->bottom=createSLlist(m);
newNode->next=HB;
HB=newNode;}
return HB;
}
void printHBlist( const HBnodePtr L){
HBnodePtr readHB=L;
while(readHB!=NULL){
printf("\n%d",readHB->key);
printSLlist(readHB->bottom);
printf("\n↓");
readHB=readHB->next; }
}
void printSLlist(const SLnodePtr L){
SLnodePtr readSL=L;
while(readSL!=NULL){
printf(" -> %d",readSL->key);
readSL=readSL->next; }
}
#include <stdlib.h>
#include<time.h>
struct SLnode{//the slave link
int key;
struct SLnode *next;
};
typedef struct SLnode *SLnodePtr;
struct HBnode{//the master link
int key;
struct HBnode *next;
SLnodePtr bottom;
};
typedef struct HBnode *HBnodePtr;
HBnodePtr HB=NULL;
HBnodePtr createHBlist(int n, int m);
SLnodePtr createSLlist(int n);
SLnodePtr flattenList(const HBnodePtr L);
void printHBlist (const HBnodePtr L );
int main(){
createHBlist(5,7);//master links and slave links' length
printf("\nDone\n");
printHBlist(HB);
}
SLnodePtr createSLlist(int n){
n=rand()%(n);
int i,r;
SLnodePtr SL=NULL;
for(i=0;i<n;i++){
SLnodePtr newNode;
newNode=malloc(sizeof(SLnodePtr));
if (newNode == NULL) {
printf("Error: malloc failed in add_to_list\n");
exit(EXIT_FAILURE);}
r=rand()%101;
printf("%d ",r);
newNode->key=r;
newNode->next=SL;
SL=newNode;
}
return SL;
}
HBnodePtr createHBlist(int n, int m){
int i,r;
srand((int)time(NULL));
for(i=0;i<n;i++){
SLnodePtr SL=NULL;
HBnodePtr newNode;
newNode=malloc(sizeof(HBnodePtr));
if (newNode == NULL){
printf("Error: malloc failed in add_to_list\n");
exit(EXIT_FAILURE);}
r=rand()%101;
newNode->key=r;
printf("\n%d link with :",r);
newNode->bottom=createSLlist(m);
newNode->next=HB;
HB=newNode;}
return HB;
}
void printHBlist( const HBnodePtr L){
HBnodePtr readHB=L;
while(readHB!=NULL){
printf("\n%d",readHB->key);
printSLlist(readHB->bottom);
printf("\n↓");
readHB=readHB->next; }
}
void printSLlist(const SLnodePtr L){
SLnodePtr readSL=L;
while(readSL!=NULL){
printf(" -> %d",readSL->key);
readSL=readSL->next; }
}

