fork download
  1.  
  2. #include "Header.h"
  3. Node *GetNode(int x){
  4. Node *p = new Node;
  5. if (p == NULL){
  6. return NULL;
  7. }
  8. else {
  9. p->Data = x;
  10. p->pNext = NULL;
  11. return p;
  12. }
  13. }
  14. void Init(List &l){
  15. l.pHead = l.pTail = NULL;
  16. }
  17.  
  18. int main(){
  19. List l;
  20. int n;
  21. cout << "ban muon nhap bao nhieu node? ";
  22. cin >> n;
  23. Input(l, n);
  24. Output(l);
  25. GiaiPhong(l);
  26. system("pause");
  27. return 0;
  28. }
  29. void AddHead(List &l, Node *p){
  30. if (l.pHead == NULL){
  31. l.pHead = l.pTail = p;
  32. }
  33. else{
  34. p->pNext = l.pHead;
  35. l.pHead = p;
  36. }
  37. }
  38.  
  39. void AddTail(List &l, Node *p){
  40. if (l.pHead == NULL){
  41. l.pHead = l.pTail = p;
  42. }
  43. else{
  44. l.pTail->pNext = p;
  45. l.pTail = p;
  46. }
  47. }
  48. void RemoveHead(List &l){
  49. Node *p = new Node;
  50. Node *k = new Node;
  51. for (Node*i = l.pHead; i; i = i->pNext){
  52. if (p != NULL){
  53. p = l.pHead;
  54. k = p->pNext;
  55. k = l.pHead;
  56. delete p;
  57. return;
  58. }
  59. }
  60. if (p == NULL){
  61. l.pHead = l.pTail = NULL;
  62. }
  63. }
  64. void RemoveTail(List &l){
  65. Node *p = new Node;
  66. Node *g = new Node;
  67. if (p != NULL){
  68. p = l.pTail;
  69. g->pNext = p;
  70. g = l.pTail;
  71. delete p;
  72. return;
  73. }
  74. else{
  75. l.pHead = l.pTail = NULL;
  76. }
  77. }
  78. void Input(List &l, int n){
  79. Init(l);
  80. for (int i = 1; i <= n; i++){
  81. int x;
  82. printf("Moi nhap data\n");
  83. scanf_s("&d", &x);
  84. Node *p = GetNode(x);
  85. AddTail(l, p);
  86. }
  87. }
  88.  
  89. void Output(List l){
  90. for (Node *p = l.pHead; p!=NULL; p = p->pNext){
  91. printf("%5d", p->Data);
  92. }
  93. }
  94. void GiaiPhong(List &l)
  95. {
  96. Node *p;
  97. while (l.pHead != NULL)
  98. {
  99. p = l.pHead;
  100. l.pHead = l.pHead->pNext;
  101. delete p;
  102. }
  103. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:2:20: fatal error: Header.h: No such file or directory
compilation terminated.
stdout
Standard output is empty