C++ writing into the heap "forward"?
-
This program is suppose to input 3 doubles and store them into heap memory. Then I have to basically reverse the heap so if I input. 50 51 52 at first it will look like this. 52 points to 51 points to 50. When I reverse it, it should read like this in the heap: 50 points to 51 points to 52. Right now I can get: 50 points to 52 points to 51. I dont know how to switch 52 and 51. here is my header file: #ifndef DOUBLE_NODE_H #define DOUBLE_NODE_H namespace Own { struct Double_node { Double_node *next; double datum; }; } #endif Here is my .cpp: #include "Double_node.h" #include <iostream> using Own::Double_node; // ----------------------------------------… // GLOBAL PARAMETERS // ----------------------------------------… const int no_temp = 3; const double temp_diff = 15.0; // ----------------------------------------… int main() { // Point to the list's head. Double_node *head = 0; Double_node *tail = 0; // Read and store several daily low temperatures. for (int i = no_temp; i > 0; --i) { double low_temp; std::cin >> low_temp; // Link the low temperature into the list. Double_node *const p = new Double_node; (*p).next = head; (*p).datum = low_temp; //THIS IS THE PART WHERE IT SHOULD SWITCH THE TWO, DO I NEED A WHILE LOOP? for (Double_node *a = p; (*a).next != 0; a = (*a).next){ double store; double store2; store = (*a).datum; store2 = (*head).datum; (*a).datum = store2; (*head).datum = store; } head = p; } // Print the daily high temperatures. for ( const Double_node *q = head; q != 0; q = (*q).next ) { const double high_temp = (*q).datum + temp_diff; std::cout << high_temp << " "; } std::cout << std::endl; return 0; }
-
Answer:
Try using different parameters at a time, and. Use it for each values.
Yahoo! Answers Visit the source
Related Q & A:
- How to Convert a C++ Structure into C# Structure?Best solution by Stack Overflow
- How to do an inverted heap implementation in JAVA?Best solution by codereview.stackexchange.com
- How to learn C# (moving from C++ to C#?Best solution by stackoverflow.com
- What are bands like Imogen Heap?Best solution by last.fm
- What is Imogen Heap's song "Hide and Seek" about?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.