标签:lin pre col lse def i++ free 输出 can
数据组织
typedef int ElemType;
typedef struct Node1 { ElemType data[MaxCol]; struct Node1* next; }DList;
typedef struct Node2 { int Row, Col; DList* next; }HList;
尾插法
void CreateTable(HList*& h) { DList* r, * s; h = (HList*)malloc(sizeof(HList)); h->next = NULL; printf("表的行数列数:"); scanf("%d%d", &h->Row, &h->Col); for (int i = 0; i < h->Row; i++) { printf("第%d行", i + 1); s = (DList*)malloc(sizeof(DList)); for (int j = 0; j < h->Col; j++) { scanf("%d", &s->data[j]); } if (h->next == NULL) { h->next = s; r = s; } if(h->next != NULL) { r->next = s; r = s; } } r->next = NULL; }
销毁
void DistroyTable(HList*& h) { DList* pre = h->next; DList* p = pre->next; while (p != NULL) { free(pre); pre = p; p = pre->next; } free(pre); free(h); }
输出
void DispTable(HList* h) { DList* p = h->next; while (p != NULL) { for (int i = 0; i < h->Col; i++) { printf("%5d", p->data[i]); } printf("\n"); p = p->next; } }
表连接运算
void LinkTable(HList* h1, HList* h2, HList*& h) { int i, j; DList* p = h1->next; DList* q, * s, * r; h = (HList*)malloc(sizeof(HList)); h->next = NULL; h->Row = 0; h->Col = h1->Col + h2->Col; printf("连接的字段是:第一个表序号,第二个表序号\n"); scanf("%d%d", &i, &j); while (p != NULL) { q = h2->next; while (q != NULL) { if (p->data[i-1] == q->data[j-1]) { s = (DList*)malloc(sizeof(DList)); for (int k = 0; k < h1->Col; k++) { s->data[k] = p->data[k]; } for (int k = 0; k < h2->Col; k++) { s->data[k + h1->Col] = q->data[k]; } if (h->next == NULL) { h->next = s; } else { r->next = s; } r = s; h->Row++; } q = q->next; } p = p->next; } r->next = NULL; }
标签:lin pre col lse def i++ free 输出 can
原文地址:https://www.cnblogs.com/KIROsola/p/11331954.html