1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| #include <cstdlib> #include <stdio.h> #include <stdlib.h>
void change(char*& p) { p = (char*)malloc(100); fgets(p, 100, stdin); }
#define MaxSize 50 typedef int ElemType; typedef struct { ElemType data[MaxSize]; int length; } SqlList;
bool insertList(SqlList& L, int i, ElemType e) { if (i < 1 || i > L.length) { return false; } for (int j = L.length; j >= i; j--) { L.data[j] = L.data[j - 1]; } L.data[i - 1] = e; L.length++;
return true; }
bool deleteList(SqlList& L, int i) { if (i < 1 || i > L.length) { return false; } for (int j = i; j < L.length; j++) { L.data[j-1] = L.data[j]; } L.length--; return true; }
void printlist(SqlList L) { for (int i = 0; i < L.length; i++) { printf("%3d", L.data[i]); } printf("\n"); }
int main() { SqlList L; L.data[0] = 6; L.data[1] = 7; L.data[2] = 8; L.length = 3; int a; scanf("%d", &a); bool ret = insertList(L, 2, a); if (ret) { printlist(L); } else { printf(""); } int d; scanf("%d",&d); bool dd = deleteList(L,d); if(dd){ printlist(L); }else { printf("false\n"); } return 0; }
|