Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5. class cnode
  6. {
  7. public:
  8. int info;
  9. cnode *pnext;
  10. };
  11.  
  12. class clist
  13. {
  14. public:
  15. cnode *phead=NULL;
  16. cnode *ptail;
  17.  
  18. clist()
  19. {
  20. phead = NULL;
  21. ptail = NULL;
  22. }
  23.  
  24. ~clist()
  25. {
  26. cnode *ptrav = phead;
  27. while (ptrav != NULL)
  28. {
  29. phead = phead->pnext;
  30. delete ptrav;
  31. ptrav = phead;
  32. }
  33. }
  34.  
  35. void Attach(cnode *pnn)
  36. {
  37. if (phead == NULL)
  38. {
  39. phead = pnn;
  40. ptail = pnn;
  41. }
  42. else
  43. {
  44. ptail->pnext = pnn;
  45. ptail = pnn;
  46. }
  47. }
  48.  
  49. /*void sortAttach(cnode *pnn)
  50. {
  51. cnode *pB = NULL;
  52. if (phead == NULL)
  53. {
  54. phead=pnn;
  55. }
  56. else
  57. {
  58. cnode *ptrav = phead;
  59. while (ptrav != NULL)
  60. {
  61. if (ptrav->info < pnn->info)
  62. {
  63. break;
  64. }
  65. pB = ptrav;
  66. ptrav = ptrav->pnext;
  67. }
  68. if (ptrav != NULL)
  69. {
  70. if (pB != NULL)
  71. {
  72. pB->pnext = pnn;
  73. pnn->pnext = ptrav;
  74. }
  75. else
  76. {
  77. pnn->pnext = ptrav;
  78. phead = pnn;
  79. }
  80. }
  81. else
  82. {
  83. pB->pnext = pnn;
  84. pnn->pnext = NULL;
  85. }
  86. }
  87. }*/
  88.  
  89. };
  90.  
  91.  
  92.  
  93. int main()
  94. {
  95. clist l[30];
  96. cnode *pnn, *sahm;
  97. int n;
  98. for (int i = 0; i < 3; i++)
  99. {
  100. cout << "enter size"<<endl;
  101. cin >> n;
  102. sahm = l[i].phead;
  103. cout << "enter info" << endl;
  104. for (int j = 0; j < n; j++)
  105. {
  106. pnn = new cnode;
  107. cin>>pnn->info;
  108. pnn->pnext = NULL;
  109. l[i].Attach(pnn);
  110. }
  111. }
  112.  
  113. for (int i = 0; i < 3; i++)
  114. {
  115. cout << "list" << i<<":"<<endl;
  116. sahm = l[i].phead;
  117.  
  118. while(sahm!=NULL)
  119. {
  120. cout << sahm->info << ", ";
  121. sahm = sahm->pnext;
  122. }
  123. cout << endl;
  124. }
  125.  
  126.  
  127. /////////////////////////////////
  128.  
  129.  
  130.  
  131. system("pause");
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement