fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <conio.h>
  4. #include <cstdlib>
  5. using namespace std;
  6. struct ThongTin
  7. {
  8. string name;
  9. string address;
  10. int old;
  11. };
  12. struct SinhVien
  13. {
  14. ThongTin imformation;
  15. SinhVien *next;
  16. };
  17.  
  18. typedef SinhVien* List;
  19.  
  20. void initializer(List &L)
  21. {
  22. L = NULL;
  23. }
  24. int length(List L)
  25. {
  26. SinhVien* Q = L;
  27. int dem = 0;
  28. while(Q!=NULL)
  29. {
  30. dem ++;
  31. Q = Q->next;
  32. }
  33. return dem;
  34. }
  35. bool isEmpty(List L)
  36. {
  37. if (L == NULL)
  38. {
  39. return true;
  40. } else return false;
  41. }
  42. void Nhap(ThongTin &Ithongtin)
  43. {
  44. cin.ignore();
  45. cout<<" Nhap Ten : "; getline(cin,Ithongtin.name);
  46. cout<<" Tuoi : "; cin>>Ithongtin.old;
  47. cin.ignore();
  48. cout<<" Dia Chi : "; getline(cin,Ithongtin.address);
  49. }
  50. SinhVien* MakeNode(SinhVien *P,ThongTin thongtin)
  51. {
  52. P = new SinhVien;
  53. P->next = NULL;
  54. P->imformation.name = thongtin.name;
  55. P->imformation.old = thongtin.old;
  56. P->imformation.address = thongtin.address;
  57. return P;
  58. }
  59. void insertFirst(List &L)
  60. {
  61. SinhVien *P;
  62. ThongTin Fthongtin;
  63. Nhap(Fthongtin);
  64. P = MakeNode(P,Fthongtin);
  65. P->next = L;
  66. L = P;
  67. }
  68. void insertK(List &L,int k){
  69. if(k<1 || k > length(L)+1)
  70. {
  71. cout<<"Vi tri khong hop le " <<endl;
  72. }
  73. else if(k == 1)
  74. {
  75. insertFirst(L);
  76. }
  77. else
  78. {
  79. ThongTin Kthongtin;
  80. SinhVien *Q = L;
  81. int vitri = 0;
  82. SinhVien*P ;
  83. P = MakeNode(P,Kthongtin);
  84. while(Q!= NULL && vitri != k-1)
  85. {
  86. vitri++;
  87. Q = Q->next;
  88. }
  89. P->next = Q->next;
  90. Q->next = P;
  91. }
  92. }
  93. void Xuat(List L)
  94. {
  95. SinhVien *Q =L;
  96. while(Q!=NULL){
  97. cout<<"Name : "<<Q->imformation.name<<endl;
  98. cout<<"Old : "<<Q->imformation.old<<endl;
  99. cout<<"Address : "<<Q->imformation.address<<endl;
  100. Q = Q->next;
  101. }
  102. }
  103. void Menu(List L)
  104. {
  105. int position;
  106. int choice;
  107. while(1){
  108. cout<<"1 : Nhap vao dau Danh Sach "<<endl;
  109. cout<<"2 : Nhap vao vi tri cho truoc"<<endl;
  110. cout<<"3 : Xuat Danh Sach "<<endl;
  111. cout<<"4 : Check Empty List "<<endl;
  112. cout<<"5 : Ket Thuc "<<endl;
  113. cout<<" Ban chon so : "; cin>>choice;
  114.  
  115. switch(choice)
  116. {
  117. case 1:
  118. insertFirst(L);
  119. break;
  120. case 2:
  121. cout<<"Import position you need add data "; cin>>position;
  122. cin.ignore();
  123. insertK(L,position);
  124. break;
  125. case 3:
  126. Xuat(L);
  127. break;
  128. case 4:
  129. if(isEmpty(L))
  130. cout<<"List is Empty"<<endl;
  131. else cout<<"List is'nt Empty"<<endl;
  132. break;
  133. case 5:
  134. exit(0);
  135. default :
  136. cout<<"Nhap so tu 1 den 4" <<endl;
  137. break;
  138. }
  139. }
  140. }
  141. int main()
  142. {
  143. List L;
  144. initializer(L);
  145. Menu(L);
  146. return 0;
  147. }
  148.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:19: fatal error: conio.h: No such file or directory
 #include <conio.h>
                   ^
compilation terminated.
stdout
Standard output is empty