spacepaste

  1.  
  2. $ ./new
  3. FOUND BRANCH START
  4. FOUND BRANCH START
  5. 0 -> 1 (data: 1)
  6. printing branches
  7. printing branch 0
  8. branch start
  9. branch choice start
  10. 1 -> 2 (data: 2)
  11. branch choice end
  12. NULL
  13. finished printing branch 0
  14. branch start
  15. printing branches
  16. printing branch 0
  17. branch choice start
  18. 1 -> 2 (data: 2)
  19. branch choice end
  20. NULL
  21. finished printing branch 0
  22. printing branch 1
  23. branch choice start
  24. 2 -> 3 (data: 8)
  25. branch choice end
  26. branch end
  27. 3 -> 4 (data: 13)
  28. NULL
  29. finished printing branch 1
  30. branch choice start
  31. printing branches
  32. printing branch 0
  33. 1 -> 2 (data: 2)
  34. branch choice end
  35. NULL
  36. finished printing branch 0
  37. 1 -> 2 (data: 2)
  38. printing branches
  39. printing branch 0
  40. branch choice end
  41. NULL
  42. finished printing branch 0
  43. branch choice end
  44. NULL
  45. printing previous
  46. NULL
  47. 3 -> 4 (data: 13)
  48. branch end
  49. branch choice end
  50. 2 -> 3 (data: 8)
  51. branch choice start
  52. branch choice end
  53. 1 -> 2 (data: 2)
  54. branch choice start
  55. branch start
  56. 0 -> 1 (data: 1)
  57. $ cat new.c
  58. #include <stdbool.h>
  59. #include <stdio.h>
  60. #include <stdlib.h>
  61. #include <string.h>
  62. #define pp(x) printf("%s = %p\n", #x, x);
  63. #define pi(x) printf("%s = %d\n", #x, x);
  64. #define pc(x) printf("%s = %c\n", #x, x);
  65. #define psize_t(x) printf("%s = %zu\n", #x, x);
  66. #define LINKED 1
  67. #define TREE 2
  68. #define NODE_TYPE TREE
  69. struct QNode
  70. {
  71. int level;
  72. int index;
  73. int ref;
  74. int data;
  75. int type;
  76. #if NODE_TYPE == LINKED
  77. struct QNode *next;
  78. #elif NODE_TYPE == TREE
  79. int next_count;
  80. struct QNode **next;
  81. #endif
  82. struct QNode* prev; // Pointer to previous node in DLL
  83. };
  84. // The queue, front stores the front node of LL and rear stores ths
  85. // last node of LL
  86. struct Queue
  87. {
  88. struct QNode *front, *rear;
  89. };
  90. ssize_t free_asm(struct Queue **q)
  91. {
  92. puts("");
  93. ssize_t frees = 0;
  94. if ((q) == NULL) return frees;
  95. if ((*q) == NULL) return frees;
  96. struct QNode *temp = NULL, *next = NULL;
  97. temp = (*q)->front;
  98. while (temp) {
  99. #if NODE_TYPE == LINKED
  100. next = (*q)->front->next;
  101. #elif NODE_TYPE == TREE
  102. // unknown, would use this
  103. /*
  104. if (node->next) {
  105. if (node->next[0]) {
  106. free(node->next[0]);
  107. nodes++;
  108. }
  109. free(node->next);
  110. nodes++;
  111. */
  112. next = (*q)->front->next[0];
  113. #endif
  114. frees++;
  115. free(temp);
  116. temp = NULL;
  117. (*q)->front = next;
  118. temp = next;
  119. }
  120. frees++;
  121. free(*q);
  122. *q = NULL;
  123. return frees;
  124. }
  125. // A C program to demonstrate linked list based implementation of queue
  126. // A linked list (LL) node to store a queue entry
  127. int index_start = -1;
  128. int ref_start = 0;
  129. int global_indent = 0;
  130. #if NODE_TYPE == LINKED
  131. #define node_init(t, i, r, d, n) t->index = i; t->ref = r; t->data = d; t->next = n; t->level = global_indent; t->prev = NULL;
  132. #elif NODE_TYPE == TREE
  133. #define node_init(t, i, r, d, nc, n) t->index = i; t->ref = r; t->data = d; t->next_count = nc; t->next = n; t->level = global_indent; t->prev = NULL;
  134. #endif
  135. #define STORE_NORMAL 1
  136. #define STORE_EMPTY 2
  137. #define NODE_TYPE_NORMAL 1
  138. #define NODE_TYPE_BRANCH_START 2
  139. #define NODE_TYPE_BRANCH_END 3
  140. #define NODE_TYPE_BRANCH_CHOICE_START 4
  141. #define NODE_TYPE_BRANCH_CHOICE_END 5
  142. #define POINTER_LIST_TYPE int
  143. POINTER_LIST_TYPE ** ptr_list = NULL;
  144. ssize_t ptr_list_size = 0;
  145. int last_ref = 0;
  146. int ptr_add(POINTER_LIST_TYPE * ptr) {
  147. if (!ptr) return -1;
  148. if (!ptr_list) {
  149. ptr_list = malloc(sizeof(*ptr_list)*2);
  150. ptr_list_size++;
  151. }
  152. else if (ptr_list) {
  153. ptr_list = realloc(ptr_list, sizeof(*ptr_list)*(ptr_list_size+1));
  154. }
  155. ptr_list[ptr_list_size-1] = ptr;
  156. ptr_list_size++;
  157. ptr_list[ptr_list_size-1] = NULL;
  158. return 0;
  159. }
  160. int ptr_print(void) {
  161. if (!ptr_list) return -1;
  162. POINTER_LIST_TYPE ** pl;
  163. for (pl = ptr_list; *pl; pl++) pp(*pl);
  164. return 0;
  165. }
  166. int ptr_set(POINTER_LIST_TYPE data) {
  167. if (!ptr_list) return -1;
  168. POINTER_LIST_TYPE ** pl;
  169. for (pl = ptr_list; *pl; pl++) **pl = data;
  170. return 0;
  171. }
  172. int ptr_set_free(void) {
  173. if (!ptr_list) return -1;
  174. POINTER_LIST_TYPE ** pl;
  175. for (pl = ptr_list; *pl; pl++) {
  176. free(*pl);
  177. *pl = NULL;
  178. }
  179. return 0;
  180. }
  181. int ptr_free(void) {
  182. if (!ptr_list) return -1;
  183. POINTER_LIST_TYPE ** pl;
  184. for (pl = ptr_list; *pl; pl++) *pl = NULL;
  185. free(ptr_list);
  186. ptr_list = NULL;
  187. ptr_list_size = 0;
  188. return 0;
  189. }
  190. // A utility function to create a new linked list node.
  191. struct QNode* newNode(int data, int type)
  192. {
  193. struct QNode *temp = (struct QNode*)malloc(sizeof(*temp));
  194. #if NODE_TYPE == LINKED
  195. if (type == STORE_NORMAL) {
  196. node_init(temp, index_start++, ref_start++, data, NULL);
  197. } else if (type == STORE_EMPTY) {
  198. node_init(temp, 0, 0, 0, NULL);
  199. }
  200. #elif NODE_TYPE == TREE
  201. if (type == STORE_NORMAL) {
  202. node_init(temp, index_start++, ref_start++, data, 0, NULL);
  203. } else if (type == STORE_EMPTY) {
  204. node_init(temp, 0, 0, 0, 0, NULL);
  205. }
  206. #endif
  207. return temp;
  208. }
  209. // A utility function to create an empty queue
  210. struct Queue *createQueue()
  211. {
  212. struct Queue *q = (struct Queue*)malloc(sizeof(*q));
  213. q->front = q->rear = NULL;
  214. return q;
  215. }
  216. int prev_type = 0;
  217. int curr_type = 0;
  218. void store_asm(struct Queue *q, int data, int type)
  219. {
  220. if (curr_type) prev_type = curr_type;
  221. curr_type = type;
  222. // Create a new LL node
  223. int t = 0;
  224. if (type == NODE_TYPE_NORMAL) t = STORE_NORMAL;
  225. else if (
  226. type == NODE_TYPE_BRANCH_START
  227. ||
  228. type == NODE_TYPE_BRANCH_END
  229. ||
  230. type == NODE_TYPE_BRANCH_CHOICE_START
  231. ||
  232. type == NODE_TYPE_BRANCH_CHOICE_END
  233. ) t = STORE_EMPTY;
  234. struct QNode *temp = newNode(data, t);
  235. temp->type = type;
  236. // If queue is empty, then new node is front and rear both
  237. if (q->rear == NULL)
  238. {
  239. temp->prev = NULL;
  240. q->front = q->rear = temp;
  241. return;
  242. }
  243. if (prev_type == NODE_TYPE_NORMAL) {
  244. if (type == NODE_TYPE_BRANCH_CHOICE_END) {
  245. // we reach a the end of a branch choice, add the address of the last reference, the pointer to the next node, to an array of pointers
  246. // last_ref = q->rear->ref;
  247. // printf("adding %d to the pointer list\n", last_ref);
  248. // ptr_add(&q->rear->ref);
  249. }
  250. }
  251. else if(type == NODE_TYPE_NORMAL && prev_type == NODE_TYPE_BRANCH_END) {
  252. // we reach a node and we where previously at a branch, set all referenced logged to the value of the current node reference, then we free the pointer list
  253. // printf("setting pointer list to %d\n", last_ref);
  254. // ptr_set(last_ref);
  255. // ptr_free();
  256. }
  257. // Add the new node at the end of queue and change rear
  258. temp->prev = q->rear;
  259. // allocate a new array for our new item
  260. #if NODE_TYPE == LINKED
  261. if (!q->rear->next) {
  262. q->rear->next = malloc(sizeof(*q->rear->next));
  263. } else {
  264. abort();
  265. }
  266. // update rear->next to point to the new item
  267. q->rear->next = temp;
  268. // update rear to point to the rear->next, which is the item we just added, updating the pointer rear from our old item to our new item
  269. q->rear = q->rear->next;
  270. #elif NODE_TYPE == TREE
  271. struct QNode * p = q->rear;
  272. if (type == NODE_TYPE_BRANCH_CHOICE_START) {
  273. while(p) {
  274. if (p->type == NODE_TYPE_BRANCH_START) {
  275. puts("FOUND BRANCH START");
  276. q->rear = p;
  277. break;
  278. }
  279. if (p->prev) p = p->prev;
  280. else p = NULL;
  281. }
  282. }
  283. // allocate a new array for our new item
  284. if (!q->rear->next) {
  285. q->rear->next_count = 1;
  286. q->rear->next = malloc(sizeof(struct QNode)*q->rear->next_count);
  287. } else {
  288. q->rear->next_count++;
  289. q->rear->next = realloc(q->rear->next, sizeof(struct QNode)*q->rear->next_count);
  290. }
  291. // update rear->next to point to the new item
  292. q->rear->next[q->rear->next_count-1] = temp;
  293. // update rear to point to the rear->next, which is the item we just added, updating the pointer rear from our old item to our new item
  294. q->rear = q->rear->next[q->rear->next_count-1];
  295. #endif
  296. }
  297. struct QNode * load_asm(struct Queue **q)
  298. {
  299. // If queue is empty, return NULL.
  300. if ((q) == NULL) return NULL;
  301. if ((*q) == NULL) return NULL;
  302. if ((*q)->front == NULL)
  303. return NULL;
  304. // Store previous front and move front one node ahead
  305. struct QNode *temp = (*q)->front;
  306. // check if front->next is NULL, if NULL it means we have reached the end of the queue
  307. #if NODE_TYPE == LINKED
  308. (*q)->front = (*q)->front->next;
  309. #elif NODE_TYPE == TREE
  310. if ((*q)->front->next) (*q)->front = (*q)->front->next[0];
  311. else (*q)->front = NULL;
  312. #endif
  313. // If front becomes NULL, then change rear also as NULL
  314. if ((*q)->front == NULL)
  315. (*q)->rear = NULL;
  316. return temp;
  317. }
  318. #define add_indent(indent) { int i = 0; for (; i < indent; i++) printf(" "); }
  319. struct Queue * list = NULL;
  320. void printnode(struct QNode * p) {
  321. int indentation = p->level;
  322. add_indent(indentation);
  323. if (p->type == NODE_TYPE_BRANCH_START) {
  324. add_indent(indentation);
  325. printf("branch start\n");
  326. }
  327. else if (p->type == NODE_TYPE_BRANCH_END) {
  328. add_indent(indentation);
  329. printf("branch end\n");
  330. }
  331. else if (p->type == NODE_TYPE_BRANCH_CHOICE_START) {
  332. add_indent(indentation);
  333. printf("branch choice start\n");
  334. }
  335. else if (p->type == NODE_TYPE_BRANCH_CHOICE_END) {
  336. add_indent(indentation);
  337. printf("branch choice end\n");
  338. }
  339. else if (p->type == NODE_TYPE_NORMAL) {
  340. add_indent(indentation);
  341. printf("%d -> %d (data: %d)\n", p->index, p->ref, p->data);
  342. }
  343. #if NODE_TYPE == TREE
  344. // pi(p->next_count)
  345. #endif
  346. }
  347. void print_prev(struct QNode * p) {
  348. puts("NULL");
  349. while(p) {
  350. printnode(p);
  351. if (p->prev) p = p->prev;
  352. else p = NULL;
  353. }
  354. }
  355. void print_(struct QNode * p) {
  356. while(p) {
  357. printnode(p);
  358. #if NODE_TYPE == LINKED
  359. p = p->next;
  360. #elif NODE_TYPE == TREE
  361. if (p->next) p = p->next[0];
  362. else p = NULL;
  363. #endif
  364. }
  365. puts("NULL");
  366. }
  367. void print(struct QNode * p) {
  368. while(p) {
  369. printnode(p);
  370. #if NODE_TYPE == LINKED
  371. p = p->next;
  372. #elif NODE_TYPE == TREE
  373. if (p->next_count) {
  374. puts("printing branches");
  375. for (int i = 0; i < p->next_count; i++) {
  376. printf("printing branch %d\n", i);
  377. print_(p->next[i]);
  378. printf("finished printing branch %d\n", i);
  379. }
  380. }
  381. if (p->next) p = p->next[0];
  382. else p = NULL;
  383. #endif
  384. }
  385. puts("NULL");
  386. }
  387. void fix(struct Queue *p);
  388. void add(struct Queue **q, int data) {
  389. if (!(*q)) (*q) = createQueue();
  390. store_asm((*q), data, NODE_TYPE_NORMAL);
  391. }
  392. void add_branch(struct Queue **q) {
  393. if (!(*q)) (*q) = createQueue();
  394. store_asm((*q), 0, NODE_TYPE_BRANCH_START);
  395. global_indent++;
  396. }
  397. void end_branch(struct Queue **q) {
  398. global_indent--;
  399. if (!(*q)) (*q) = createQueue();
  400. store_asm((*q), 0, NODE_TYPE_BRANCH_END);
  401. }
  402. void add_branch_choice(struct Queue **q) {
  403. if (!(*q)) (*q) = createQueue();
  404. store_asm((*q), 0, NODE_TYPE_BRANCH_CHOICE_START);
  405. global_indent++;
  406. }
  407. void end_branch_choice(struct Queue **q) {
  408. global_indent--;
  409. if (!(*q)) (*q) = createQueue();
  410. // if we have a branch_end, we need to go backwards in out linked list to the node that came before the branch start
  411. store_asm((*q), 0, NODE_TYPE_BRANCH_CHOICE_END);
  412. }
  413. int main(void) {
  414. index_start = 0;
  415. ref_start = 1;
  416. /* attempt to visualize this in a expression grammar
  417. root ::= 0 A 61
  418. A ::=
  419. 1 2 B
  420. 5 6 C
  421. B ::=
  422. 3 4
  423. C ::=
  424. 7 8 D
  425. D ::=
  426. 9 10 F R
  427. 57 58 S
  428. F ::=
  429. G 41 42 P 45 46 47
  430. 48 49 Q 52 53 54
  431. G ::=
  432. 11 12 H
  433. 15 16 I
  434. H ::=
  435. 13 14
  436. I ::=
  437. 17 18 J
  438. J ::=
  439. 19 20 K N
  440. 37 38 O
  441. K ::=
  442. 21 22 L 25 26 27
  443. 28 29 M 32 33 34
  444. L ::=
  445. 23 24
  446. M ::=
  447. 30 31
  448. N ::=
  449. 35 36
  450. O ::=
  451. 39 40
  452. P ::=
  453. 43 44
  454. Q ::=
  455. 50 51
  456. R ::=
  457. 55 56
  458. S ::=
  459. 59 60
  460. structure:
  461. root: 0 A 61 > NULL
  462. A: 1 2 B
  463. B: 3 4 > 61 // currently 4 > 25
  464. A: 5 6 C
  465. C: 7 8 D
  466. D: 9 10 F R
  467. F: G 41 42 P 45 46 47 > 55 (R) // currently 47 > 52
  468. G: 11 12 H
  469. H: 13 14 > 41 // currently 14 > 25
  470. G: 15 16 I
  471. I: 16 18 J
  472. J: 19 20 K N
  473. K: 21 22 L 25 26 27 > 35 (N) // currently 27 > 32
  474. L: 23 24 > 25
  475. K: 28 29 M 32 33 34 > 35 (N)
  476. M: 30 31 > 32
  477. N: 35 36 > 41
  478. J: 37 38 O
  479. O: 39 40 > 41
  480. P: 43 44 > 45
  481. F: 48 49 Q 52 53 54 > 55 (R)
  482. Q: 50 51 > 52
  483. R: 55 56 > 61
  484. D: 57 58 S
  485. S: 59 60 > 61
  486. add(&list, 1);
  487. add_branch(&list);
  488. add_branch_choice(&list);
  489. add(&list, 2);
  490. add(&list, 3);
  491. add_branch(&list);
  492. add_branch_choice(&list);
  493. add(&list, 4);
  494. add(&list, 5);
  495. end_branch_choice(&list);
  496. end_branch(&list);
  497. end_branch_choice(&list);
  498. add_branch_choice(&list);
  499. add(&list, 6);
  500. add(&list, 7);
  501. add_branch(&list);
  502. add_branch_choice(&list);
  503. add(&list, 8);
  504. add(&list, 9);
  505. add_branch(&list);
  506. add_branch_choice(&list);
  507. add(&list, 10);
  508. add(&list, 11);
  509. add_branch(&list);
  510. add_branch_choice(&list);
  511. add_branch(&list);
  512. add_branch_choice(&list);
  513. add(&list, 12);
  514. add(&list, 13);
  515. add_branch(&list);
  516. add_branch_choice(&list);
  517. add(&list, 14);
  518. add(&list, 15);
  519. end_branch_choice(&list);
  520. end_branch(&list);
  521. end_branch_choice(&list);
  522. add_branch_choice(&list);
  523. add(&list, 16);
  524. add(&list, 17);
  525. add_branch(&list);
  526. add_branch_choice(&list);
  527. add(&list, 18);
  528. add(&list, 19);
  529. add_branch(&list);
  530. add_branch_choice(&list);
  531. add(&list, 20);
  532. add(&list, 21);
  533. add_branch(&list);
  534. add_branch_choice(&list);
  535. add(&list, 22);
  536. add(&list, 23);
  537. add_branch(&list);
  538. add_branch_choice(&list);
  539. add(&list, 24);
  540. add(&list, 25);
  541. end_branch_choice(&list);
  542. end_branch(&list);
  543. add(&list, 26);
  544. add(&list, 27);
  545. add(&list, 28);
  546. end_branch_choice(&list);
  547. add_branch_choice(&list);
  548. add(&list, 29);
  549. add(&list, 30);
  550. add_branch(&list);
  551. add_branch_choice(&list);
  552. add(&list, 31);
  553. add(&list, 32);
  554. end_branch_choice(&list);
  555. end_branch(&list);
  556. add(&list, 33);
  557. add(&list, 34);
  558. add(&list, 35);
  559. end_branch_choice(&list);
  560. end_branch(&list);
  561. add_branch(&list);
  562. add_branch_choice(&list);
  563. add(&list, 36);
  564. add(&list, 37);
  565. end_branch_choice(&list);
  566. end_branch(&list);
  567. end_branch_choice(&list);
  568. add_branch_choice(&list);
  569. add(&list, 38);
  570. add(&list, 39);
  571. add_branch(&list);
  572. add_branch_choice(&list);
  573. add(&list, 40);
  574. add(&list, 41);
  575. end_branch_choice(&list);
  576. end_branch(&list);
  577. end_branch_choice(&list);
  578. end_branch(&list);
  579. end_branch_choice(&list);
  580. end_branch(&list);
  581. end_branch_choice(&list);
  582. end_branch(&list);
  583. add(&list, 42);
  584. add(&list, 43);
  585. add_branch(&list);
  586. add_branch_choice(&list);
  587. add(&list, 44);
  588. add(&list, 45);
  589. end_branch_choice(&list);
  590. end_branch(&list);
  591. add(&list, 46);
  592. add(&list, 47);
  593. add(&list, 48);
  594. end_branch_choice(&list);
  595. add_branch_choice(&list);
  596. add(&list, 49);
  597. add(&list, 50);
  598. add_branch(&list);
  599. add_branch_choice(&list);
  600. add(&list, 51);
  601. add(&list, 52);
  602. end_branch_choice(&list);
  603. end_branch(&list);
  604. add(&list, 53);
  605. add(&list, 54);
  606. add(&list, 55);
  607. end_branch_choice(&list);
  608. end_branch(&list);
  609. add_branch(&list);
  610. add_branch_choice(&list);
  611. add(&list, 56);
  612. add(&list, 57);
  613. end_branch_choice(&list);
  614. end_branch(&list);
  615. end_branch_choice(&list);
  616. add_branch_choice(&list);
  617. add(&list, 58);
  618. add(&list, 59);
  619. add_branch(&list);
  620. add_branch_choice(&list);
  621. add(&list, 60);
  622. add(&list, 61);
  623. end_branch_choice(&list);
  624. end_branch(&list);
  625. end_branch_choice(&list);
  626. end_branch(&list);
  627. end_branch_choice(&list);
  628. end_branch(&list);
  629. end_branch_choice(&list);
  630. end_branch(&list);
  631. add(&list, 62);
  632. */
  633. /* attempt to visualize this in a expression grammar
  634. root ::= 1 A 13
  635. A ::=
  636. 2 3 B 6
  637. 7 8 C
  638. B ::=
  639. 4
  640. C ::=
  641. 9 10 D
  642. D ::=
  643. 11
  644. structure:
  645. root: 1 A 13 > NULL
  646. A: 2 3 B 6 > 13
  647. B: 4 5 > 6
  648. A: 7 8 C
  649. C: 9 10 D
  650. D: 11 > 13
  651. */
  652. add(&list, 1);
  653. add_branch(&list);
  654. add_branch_choice(&list);
  655. add(&list, 2);
  656. // add(&list, 3);
  657. // add_branch(&list);
  658. // add_branch_choice(&list);
  659. // add(&list, 4);
  660. // add(&list, 5);
  661. // end_branch_choice(&list);
  662. // end_branch(&list);
  663. // add(&list, 6);
  664. end_branch_choice(&list);
  665. add_branch_choice(&list);
  666. // add(&list, 7);
  667. add(&list, 8);
  668. // add_branch(&list);
  669. // add_branch_choice(&list);
  670. // add(&list, 9);
  671. // add(&list, 10);
  672. // add_branch(&list);
  673. // add_branch_choice(&list);
  674. // add(&list, 11);
  675. // add(&list, 12);
  676. // end_branch_choice(&list);
  677. // end_branch(&list);
  678. // end_branch_choice(&list);
  679. // end_branch(&list);
  680. end_branch_choice(&list);
  681. end_branch(&list);
  682. add(&list, 13);
  683. print(list->front);
  684. puts("printing previous");
  685. print_prev(list->rear);
  686. // fix(list);
  687. // this part should be left to the garbage collector to clean up
  688. #if NODE_TYPE == LINKED
  689. psize_t(free_asm(&list));
  690. #endif
  691. return 0;
  692. }
  693. void print_indentation(struct QNode * p, int indentation) {
  694. printf("printing nodes with an indentation level of %d\n", indentation);
  695. while(p) {
  696. if (p->level == indentation) {
  697. add_indent(indentation);
  698. if (p->type == NODE_TYPE_BRANCH_START) {
  699. add_indent(indentation);
  700. printf("branch start\n");
  701. }
  702. else if (p->type == NODE_TYPE_BRANCH_END) {
  703. add_indent(indentation);
  704. printf("branch end\n");
  705. }
  706. else if (p->type == NODE_TYPE_BRANCH_CHOICE_START) {
  707. add_indent(indentation);
  708. printf("branch choice start\n");
  709. }
  710. else if (p->type == NODE_TYPE_BRANCH_CHOICE_END) {
  711. add_indent(indentation);
  712. printf("branch choice end\n");
  713. }
  714. else if (p->type == NODE_TYPE_NORMAL) {
  715. add_indent(indentation);
  716. printf("%d -> %d (data: %d)\n", p->index, p->ref, p->data);
  717. }
  718. }
  719. #if NODE_TYPE == LINKED
  720. p = p->next;
  721. #elif NODE_TYPE == TREE
  722. if (p->next) p = p->next[0];
  723. else p = NULL;
  724. #endif
  725. }
  726. }
  727. void fix(struct Queue * list) {
  728. int indent = 0;
  729. print_indentation(list->front, indent++);
  730. print_indentation(list->front, indent++);
  731. print_indentation(list->front, indent++);
  732. print_indentation(list->front, indent++);
  733. print_indentation(list->front, indent++);
  734. puts("NULL");
  735. }
  736.