{{{//============================================================================ // Name : Ladder.cpp // Author : chobocho // Version : // Copyright : chobocho at com // Description : Ladder // Date : 2010. 12. 26 //============================================================================ #include #include using namespace std; /* Example 1 2 3 | | | +---+ | 10 | | | | +---+ 20 | | | +---+ | 30 | | | | | | A B C (1, 2, 10) => (1, 10) (2, 3, 20) => (2, 20) (1, 2, 30) => (1, 30) */ int main() { priority_queue > ladder; int node[3] = { 10 << 8 | 1, /* (1, 2, 10) => (1, 10) => (10 << 8 | 1) */ 20 << 8 | 2, /* (2, 3, 20) => (2, 20) */ 30 << 8 | 1 /* (1, 2, 30) => (1, 30) */ }; int temp_node; char result[3] = { 'A', 'B', 'C' }; char temp_char; for (int i = 0; i < 3; i++) { ladder.push(node[i]); } for (int i = 0; i < 3; i++) { temp_node = (ladder.top() & 0xF) - 1; ladder.pop(); temp_char = result[ temp_node ]; result [ temp_node ] = result [ temp_node + 1]; result [ temp_node + 1 ] = temp_char; } cout << "================================" << endl; cout << result[0] << " " << result[1] << " " << result[2] << endl; cout << "================================" << endl; return 0; }}}}