fork download
  1. #ifndef BLIST_H
  2. #define BLIST_H
  3.  
  4. #include <stdio.h>
  5.  
  6. typedef struct {
  7. int BlockID; // 0, 1, ..., 9
  8. int Direction; // 0, 1
  9. } bSHAPE;
  10.  
  11. #define MAXLENGTH (100)
  12. typedef struct {
  13. int L;
  14. int R;
  15. bSHAPE elem[MAXLENGTH];//要素を格納する配列
  16. } bLIST;
  17.  
  18.  
  19.  
  20. #endif
  21.  
  22.  
  23. void B_makeEmpty(bLIST *x) {// リストを初期化する
  24. x->L = x->R = 0;
  25. }
  26.  
  27. int B_isEmpty(bLIST *x) {// リストが空であれば1を,そうでなければ0を返す
  28. return (x->L == x->R);
  29. }
  30.  
  31. int B_size(bLIST *x) {// リストの要素数を返す
  32. return x->R - x->L;
  33. }
  34.  
  35. int B_isFull(bLIST *x) {// リストが一杯であれば1を,そうでなければ0を返す
  36. return (B_size(x)==MAXLENGTH);
  37. }
  38.  
  39. static int pos(int i) {
  40. while (i < 0) i += MAXLENGTH;
  41. return i%MAXLENGTH;
  42. }
  43.  
  44. void B_pushFront(bLIST *x, bSHAPE e) {// リストの先頭に要素eを追加する
  45. int p = pos(--x->L);
  46. x->elem[p] = e;
  47. }
  48.  
  49. void B_pushBack(bLIST *x, bSHAPE e) {// リストの末尾に要素eを追加する
  50. int p = pos(x->R++);
  51. x->elem[p] = e;
  52. }
  53.  
  54. bSHAPE B_popFront(bLIST *x) {// リストの先頭から要素を取り出す
  55. int p = pos(x->L++);
  56. return x->elem[p];
  57. }
  58.  
  59. bSHAPE B_popBack(bLIST *x) {// リストの末尾から要素を取り出す
  60. int p = pos(--x->R);
  61. return x->elem[p];
  62. }
  63.  
  64. bSHAPE B_retrieve(bLIST *x, int i) {// リストのi番目の要素を返す
  65. int p = pos(x->L+i);
  66. return x->elem[p];
  67. }
  68.  
  69. void B_swap(bLIST *x, int i, int j) {// リストのi番目とj番目の要素を入れ替える
  70. int p = pos(x->L+i);
  71. int q = pos(x->L+j);
  72. bSHAPE temp = x->elem[p];
  73. x->elem[p] = x->elem[q];
  74. x->elem[q] = temp;
  75. }
  76.  
  77. void B_printList(bLIST *x) {// リストの内容をプリントする
  78. printf("[");
  79. for (int i = 0; i < B_size(x); i++){
  80. if (i > 0) printf(", ");
  81. bSHAPE e = B_retrieve(x, i);
  82. printf("(%d,%d)", e.BlockID, e.Direction);
  83. }
  84. printf("]");
  85. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty