是我插入方法不对吗?还是不可以这样打印啊,打印长度一直是0…
刚学还没入门就入土了😭
4条回答 默认 最新
- qzjhjxj 2022-07-06 03:13关注
供参考:
#include <stdio.h> #include <stdlib.h> #define MaxSize 128 typedef struct Sql { int data[MaxSize]; int Length; }SeqList; void InitList(SeqList* L) { (*L).Length = 0; } bool ListInsert(SeqList* L, int i, int e) { if (i < 1 || i > (*L).Length + 1) return false; if ((*L).Length > MaxSize) return false; for (int j = (*L).Length; j > i - 1; j--) (*L).data[j] = (*L).data[j - 1]; (*L).data[i - 1] = e; (*L).Length++; return true; } void PrintList(SeqList L) { for (int i = 0; i < L.Length; i++) printf("%d ", L.data[i]); printf("\n"); } int main() { SeqList L; InitList(&L); ListInsert(&L, 1, 1); ListInsert(&L, 2, 3); ListInsert(&L, 3, 5); ListInsert(&L, 2, 7); ListInsert(&L, 1, 9); printf("%d\n", L.Length); PrintList(L); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报