#include <stdio.h>
#include <malloc.h>
#define LISTSIZE 10
typedef struct
{
char *elem;
int length;
int listsize;
}SqList;
static void InitList_Sq(SqList *L);
static void ListInsert_Sq(SqList *L, int n);
static void ListMerge_Sq(SqList *L1, SqList *L2, SqList *L3);
static void DestroyList_Sq(SqList *L);
static void Print(SqList *L);
int main(void)
{
SqList L1, L2, L3;
InitList_Sq(&L1);
ListInsert_Sq(&L1, LISTSIZE);
Print(&L1);
InitList_Sq(&L2);
ListInsert_Sq(&L2, LISTSIZE);
Print(&L2);
ListMerge_Sq(&L1, &L2, &L3);
Destroy_Sq(&L1);
Destroy_Sq(&L2);
print(&L3);
return 0;
}
static void InitList_Sq(SqList *L)
{
(*L).elem = (char*)malloc(LISTSIZE * sizeof(char));
if (!(*L).elem) exit(1);
(*L).length = 0;
(*L).listsize = LISTSIZE;
}
static void ListInsert_Sq(SqList *L, int n)
{
int i;
for (i = 0; i < n; i++)
{
Printf("Enter the char:\n");
scanf("%c",&((*L).elem[i]));
}
}
static void ListMerge_Sq(SqList *L1, SqList *L2, SqList *L3)
{
int i = 0, j = 0;
(*L3).elem = (char*)molloc(2 * LISTSIZE * sizeof(char));
if (!(*L3).elem) exit(1);
while (i < (*L1).listsize)
(*L3).elem[i++] = (*L1).elem[i++];
i = i-1;
while (j < (*L2).listsize)
(*L3).elem[i++] = (*L3).elem[j++];
}
static void DestroyList_Sq(SqList *L)
{
if ((*L).elem == NULL) exit(1);
free((*L).elem);
(*L).elem = NULL;
}
static void Print(SqList *L)
{
int i=0;
while (i < (*L).listsize)
{
printf("%d ",(*L).elem[i++]);
}
printf("\n");
}