Advertisement
medal893

p07test

May 31st, 2020
706
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. struct list {
  7. int Level;
  8. int inspec;
  9. int Chain; //Not used.
  10. list *next;
  11. list *forward;
  12. };
  13.  
  14. int main() {
  15. ifstream iFile;
  16. ofstream oFile;
  17. iFile.open("input.txt");
  18. // oFile.open("Fixed.txt");
  19.  
  20.  
  21. int breakpoint = 0;
  22. int runtime = 0;
  23.  
  24.  
  25.  
  26. while (true) {
  27. //Basic Variation declaration.
  28. list *head, *insert, *end;
  29. list*pin1,*current;
  30. head = new list;
  31. insert = new list;
  32. end = new list;
  33. int temp1, temp2;
  34. pin1 = head;
  35. head->next = end;
  36. head->forward = head;
  37. head->Level = 200000000;
  38. int pairs2 = 0;
  39. end->forward = pin1;
  40. end->inspec = 0;
  41. end->Level = 0;
  42. //--------------------
  43. do {
  44. iFile >> temp1>>temp2;
  45. // cout << temp1 << " " << temp2 << endl;
  46. if (temp2 == 0) {
  47. pairs2 = pairs2 + 1;
  48. }
  49.  
  50. if (pairs2 >=3) {
  51. pairs2 = 0;
  52. // cout << "Detact pairs2>=2";
  53. goto exit;
  54. }
  55. // cout << "pairs2 = " << pairs2<<endl;
  56. // cout << temp1 << " " << temp2 << endl;
  57. // cout << temp1 << " " << temp2;
  58. insert->Level = temp2;
  59. insert->inspec = temp1;
  60.  
  61. //Always chain forward
  62. //Iterator to first smaller;
  63. pin1 = head;
  64. //---------------- Iterator mover towards.
  65. while (true) {
  66. //cout << pin1->Level << endl;
  67. if (pin1->Level == temp2) {
  68. pin1->inspec = pin1->inspec + temp1;
  69. breakpoint = 1;
  70. break;
  71. }
  72. else if (pin1->Level < temp2) {
  73. break;
  74. }
  75. pin1 = pin1->next;
  76. // cout << pin1->Level << endl;
  77. } //Iterator mover towards;
  78. if (breakpoint == 1) {
  79. breakpoint = 0;
  80. continue;
  81. }
  82. //--------------
  83. if (insert->Level >= pin1->Level) {
  84. //Insert at front
  85. pin1->forward->next = insert;
  86. insert->forward = pin1->forward;
  87. pin1->forward = insert;
  88. insert->next = pin1;
  89. }
  90. /* else {
  91. //insert at backward
  92. insert->next = pin1->next;
  93. insert->forward = pin1;
  94. pin1->next = insert;
  95. insert->next->forward = insert;
  96.  
  97. }*/
  98. // cout << insert->Level << " " << insert->inspec << endl;
  99. insert = new list;
  100. } while (!iFile.eof());
  101. exit:
  102. // cout << "Success Exit";
  103. cout << "Head->";
  104. // list *current;
  105. current = head;
  106. while (true) {
  107. current = current->next;
  108. cout << current->inspec << "x^" << current->Level;
  109. if (current->Level != 0) cout << " + ";
  110. else cout << " -> NULL\n";
  111. if (current->Level == 0) break;
  112. }
  113. runtime++;
  114. if (runtime == 3) break;
  115. /* delete head;
  116. delete insert;
  117. delete end;
  118. delete pin1;
  119. delete current;*/
  120. }
  121. cout << endl << endl;
  122. system("PAUSE");
  123. return 0;
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement