fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "doublylinklist.h"
  4.  
  5. void init_list(list_datatype *list) {
  6. list->head = list->tail = NULL;
  7. }
  8.  
  9. void insert_node(list_datatype *list, int x) {
  10. doubly_node *temperate = (doubly_node*)malloc(sizeof(doubly_node));
  11. temperate->data = x;
  12. if(list->head == NULL) {
  13. list->head = temperate;
  14. temperate->prev = NULL;
  15. list->tail = temperate;
  16. temperate->next = NULL;
  17. } else if (list->tail == NULL){
  18. list->head = temperate;
  19. temperate->prev = NULL;
  20. list->tail = temperate;
  21. temperate->next = NULL;
  22. } else {
  23. //chen dau
  24. temperate->next = list->head;
  25. list->head->prev = temperate;
  26. list->head = temperate;
  27. temperate->prev = NULL;
  28.  
  29. }
  30. }
  31. // xoa dau
  32. void delete_node(list_datatype *list) {
  33. doubly_node *temperate = list->head;
  34. list->head = temperate->next;
  35. list->head->prev = NULL;
  36. free(temperate);
  37. }
  38.  
  39. void display(list_datatype list) {
  40. doubly_node *temperate = list.head;
  41. while(temperate!=NULL) {
  42. // printf("%p %d ",temperate, temperate->data);
  43. printf("%d ",temperate->data);
  44. temperate = temperate->next;
  45. }
  46. printf("\n");
  47. }
  48.  
  49. void display_invert(list_datatype list) {
  50. doubly_node *temperate = list.tail;
  51. while(temperate!=NULL) {
  52. // printf("%p %d ",temperate, temperate->data);
  53. printf("%d ",temperate->data);
  54. temperate = temperate->prev;
  55. }
  56. printf("\n");
  57. }
  58.  
  59. int main(int argc, char const *argv[])
  60. {
  61. list_datatype list;
  62. init_list(&list);
  63. insert_node(&list,1);
  64. insert_node(&list,2);
  65. insert_node(&list,3);
  66. insert_node(&list,6);
  67. insert_node(&list,7);
  68. insert_node(&list,8);
  69. insert_node(&list,9);
  70. insert_node(&list,10);
  71. display(list);
  72. display_invert(list);
  73. delete_node(&list);
  74. delete_node(&list);
  75. delete_node(&list);
  76. delete_node(&list);
  77. delete_node(&list);
  78. display(list);
  79. display_invert(list);
  80. return 0;
  81. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:10: fatal error: doublylinklist.h: No such file or directory
 #include "doublylinklist.h"
          ^~~~~~~~~~~~~~~~~~
compilation terminated.
stdout
Standard output is empty