fork(2) download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. typedef int item; //kieu du lieu
  5. struct Node
  6. {
  7. item Data;
  8. Node * Next;
  9. };
  10. struct Queue
  11. {
  12. Node * Front, *Rear; //Node dau va Node cuoi
  13. int count; //dem so phan tu
  14. };
  15.  
  16. void Init (Queue &Q); //khoi tao Queue rong
  17. int Isempty(Queue Q); //kiem tra Queue rong
  18. void Push(Queue &Q, item x); //them phan tu vao cuoi hang doi
  19. int Pop(Queue &Q); //Loai bo phan tu khoi dau hang doi
  20. int Qfront (Queue Q); //xem thong tin phan tu dau hang doi
  21. Node *MakeNode(item x); //tao 1 Node
  22. void Input (Queue &Q); //Nhap
  23. void Output(Queue Q); //Xuat
  24.  
  25. void Init(Queue &Q)
  26. {
  27. Q.Front = Q.Rear = NULL;
  28. Q.count = 0;
  29. }
  30. int Isempty (Queue Q) //kiem tra Queue rong
  31. {
  32. if (Q.count == 0) //so phan tu = 0 => rong
  33. return 1;
  34. return 0;
  35. }
  36.  
  37. Node *MakeNode(item x) //tao 1 Node
  38. {
  39. Node *P = (Node*) malloc(sizeof(Node));
  40. P->Next = NULL;
  41. P->Data = x;
  42. return P;
  43. }
  44.  
  45. void Push(Queue &Q, item x) //them phan tu vao cuoi Queue
  46. {
  47. Node *P = MakeNode(x); //Neu Q rong
  48. if (Isempty(Q))
  49. {
  50. Q.Front = Q.Rear = P; //dau va cuoi deu tro den P
  51. }
  52. else //Khong rong
  53. {
  54. Q.Rear->Next = P;
  55. Q.Rear = P;
  56. }
  57. Q.count ++ ; //tang so phan tu len
  58. }
  59.  
  60. int Pop(Queue &Q) //Loai bo phan tu khoi dau hang doi
  61. {
  62. if (Isempty(Q))
  63. {
  64. printf("Hang doi rong !");
  65. return 0;
  66. }
  67. else
  68. {
  69. item x = Q.Front->Data;
  70. if (Q.count == 1) //neu co 1 phan tu
  71. Init(Q);
  72. else
  73. Q.Front = Q.Front->Next;
  74. Q.count --;
  75. return x; //tra ve phan tu lay ra
  76. }
  77. }
  78.  
  79. void Input (Queue &Q) //nhap hang doi
  80. {
  81. int i=0;
  82. item x;
  83. do
  84. {
  85. i++;
  86. printf ("Nhap phan tu thu %d : ",i);
  87. scanf("%d",&x);
  88. if (x != 0) Push(Q,x);
  89. } while(x != 0); //nhap 0 de ket thuc
  90. }
  91.  
  92. void Output(Queue Q)
  93. {
  94. Node *P = Q.Front;
  95. while (P != NULL)
  96. {
  97. printf("%d ",P->Data);
  98. P = P->Next;
  99. }
  100. printf("\n");
  101. }
  102.  
  103. int main()
  104. {
  105. Queue Q;
  106. Init(Q);
  107. Input(Q);
  108. Output(Q);
  109.  
  110. int lua_chon;
  111. printf("Moi ban chon phep toan voi DS LKD:");
  112. printf("\n1: Kiem tra Queue rong");
  113. printf("\n2: Them phan tu vao Queue");
  114. printf("\n3: Xoa phan tu trong Queue");
  115. printf("\n4: Xuat Queue");
  116. printf("\n5: Thoat");
  117. do
  118. {
  119. printf("\nBan chon: ");
  120. scanf("%d",&lua_chon);
  121. switch (lua_chon)
  122. {
  123. case 1:
  124. {
  125. if (Isempty(Q)) printf("Queue rong !");
  126. else printf ("Queue khong rong !");
  127. break;
  128. }
  129. case 2:
  130. {
  131. item x;
  132. printf ("Nhap phan tu can chen vao Queue: ");
  133. scanf("%d",&x);
  134. Push(Q,x);
  135. break;
  136. }
  137. case 3:
  138. {
  139. Pop(Q);
  140. break;
  141. }
  142. case 4:
  143. {
  144. Output(Q);
  145. break;
  146. }
  147. case 5: break;
  148. }
  149. }while (lua_chon !=5);
  150. return 0;
  151. }
  152.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:8:2: error: unknown type name ‘Node’
prog.c:12:2: error: unknown type name ‘Node’
prog.c:16:18: error: expected ‘)’ before ‘&’ token
prog.c:17:13: error: unknown type name ‘Queue’
prog.c:18:17: error: expected ‘)’ before ‘&’ token
prog.c:19:15: error: expected ‘)’ before ‘&’ token
prog.c:20:13: error: unknown type name ‘Queue’
prog.c:21:1: error: unknown type name ‘Node’
prog.c:22:19: error: expected ‘)’ before ‘&’ token
prog.c:23:13: error: unknown type name ‘Queue’
prog.c:25:17: error: expected ‘)’ before ‘&’ token
prog.c:30:14: error: unknown type name ‘Queue’
prog.c:37:1: error: unknown type name ‘Node’
prog.c: In function ‘MakeNode’:
prog.c:39:2: error: unknown type name ‘Node’
prog.c:39:13: error: ‘Node’ undeclared (first use in this function)
prog.c:39:13: note: each undeclared identifier is reported only once for each function it appears in
prog.c:39:18: error: expected expression before ‘)’ token
prog.c:40:3: error: request for member ‘Next’ in something not a structure or union
prog.c:41:3: error: request for member ‘Data’ in something not a structure or union
prog.c: At top level:
prog.c:45:17: error: expected ‘)’ before ‘&’ token
prog.c:60:15: error: expected ‘)’ before ‘&’ token
prog.c:79:19: error: expected ‘)’ before ‘&’ token
prog.c:92:13: error: unknown type name ‘Queue’
prog.c: In function ‘main’:
prog.c:105:5: error: unknown type name ‘Queue’
prog.c:106:5: warning: implicit declaration of function ‘Init’ [-Wimplicit-function-declaration]
prog.c:107:5: warning: implicit declaration of function ‘Input’ [-Wimplicit-function-declaration]
prog.c:108:5: warning: implicit declaration of function ‘Output’ [-Wimplicit-function-declaration]
prog.c:125:5: warning: implicit declaration of function ‘Isempty’ [-Wimplicit-function-declaration]
prog.c:134:5: warning: implicit declaration of function ‘Push’ [-Wimplicit-function-declaration]
prog.c:139:5: warning: implicit declaration of function ‘Pop’ [-Wimplicit-function-declaration]
stdout
Standard output is empty