Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <fstream>
- using namespace std;
- struct list {
- int Level;
- int inspec;
- int Chain; //Not used.
- list *next;
- list *forward;
- };
- int main() {
- ifstream iFile;
- ofstream oFile;
- iFile.open("input.txt");
- // oFile.open("Fixed.txt");
- int breakpoint = 0;
- int runtime = 0;
- while (true) {
- //Basic Variation declaration.
- list *head, *insert, *end;
- list*pin1,*current;
- head = new list;
- insert = new list;
- end = new list;
- int temp1, temp2;
- pin1 = head;
- head->next = end;
- head->forward = head;
- head->Level = 200000000;
- int pairs2 = 0;
- end->forward = pin1;
- end->inspec = 0;
- end->Level = 0;
- //--------------------
- do {
- iFile >> temp1>>temp2;
- // cout << temp1 << " " << temp2 << endl;
- if (temp2 == 0) {
- pairs2 = pairs2 + 1;
- }
- if (pairs2 >=3) {
- pairs2 = 0;
- // cout << "Detact pairs2>=2";
- goto exit;
- }
- // cout << "pairs2 = " << pairs2<<endl;
- // cout << temp1 << " " << temp2 << endl;
- // cout << temp1 << " " << temp2;
- insert->Level = temp2;
- insert->inspec = temp1;
- //Always chain forward
- //Iterator to first smaller;
- pin1 = head;
- //---------------- Iterator mover towards.
- while (true) {
- //cout << pin1->Level << endl;
- if (pin1->Level == temp2) {
- pin1->inspec = pin1->inspec + temp1;
- breakpoint = 1;
- break;
- }
- else if (pin1->Level < temp2) {
- break;
- }
- pin1 = pin1->next;
- // cout << pin1->Level << endl;
- } //Iterator mover towards;
- if (breakpoint == 1) {
- breakpoint = 0;
- continue;
- }
- //--------------
- if (insert->Level >= pin1->Level) {
- //Insert at front
- pin1->forward->next = insert;
- insert->forward = pin1->forward;
- pin1->forward = insert;
- insert->next = pin1;
- }
- /* else {
- //insert at backward
- insert->next = pin1->next;
- insert->forward = pin1;
- pin1->next = insert;
- insert->next->forward = insert;
- }*/
- // cout << insert->Level << " " << insert->inspec << endl;
- insert = new list;
- } while (!iFile.eof());
- exit:
- // cout << "Success Exit";
- cout << "Head->";
- // list *current;
- current = head;
- while (true) {
- current = current->next;
- cout << current->inspec << "x^" << current->Level;
- if (current->Level != 0) cout << " + ";
- else cout << " -> NULL\n";
- if (current->Level == 0) break;
- }
- runtime++;
- if (runtime == 3) break;
- /* delete head;
- delete insert;
- delete end;
- delete pin1;
- delete current;*/
- }
- cout << endl << endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement