//Metodo para invertir las notas en la estructura de lista doblemente enlazada. void invertirListaDoblementeEnlazada(){ Nota temp; for(int i=0 ; i<listaDoblementeEnlazada.length() ; i++){ temp = listaDoblementeEnlazada.remove(i); pila.push(temp); } while(pila.length()!=0){ listaDoblementeEnlazada.append(pila.pop() ); } }
//Metodo para invertir las notas en la estructura cola. void invertirCola(){ Nota temp; for(int i=0;i<cola.length();i++){ temp=cola.dequeue(); pila.push(temp); } while(pila.length()!=0){ cola.enqueue(pila.pop() ); } }
int main() { LStack test; test.push('a'); test.push('b'); test.push('c'); test.pop(); test.print_stack(); test.print_stack(); }
std::string TowerHanoi::showTowers() { std::string lines[this->rods][this->discs + 1]; for (int i = 0; i < (int)sizeof(this->towers); i++) { if ((this->towers[i] != NULL) && (i < this->rods)) { LStack<Disc>* stack = this->towers[i]; LinkedList<Disc>* list = stack->getList(); int space_lines = (this->discs - list->getSize()); int index = 0; for (int l = 0; l < space_lines; l++) { string white_space; for (int s = 0; s < ((2 * this->discs - 1) + 2); s++) { white_space += ' '; } lines[i][index++] = white_space; } for (Node<Disc>* current = list->getHead(); current != NULL; current = current->link()) { if (current != NULL) { lines[i][index++] = current->data()->getValue(); } } string separator_space; int separator_count = ((2 * this->discs - 1) + 2); for (int s = 0; s < separator_count; s++) { if (s == (separator_count / 2)) { stringstream result; result << (i + 1); separator_space += result.str(); } else { separator_space += '-'; } } lines[i][index++] = separator_space; } } std::string tower_str; for (int i = 0; i < this->discs + 1; i++) { for (int rod = 0; rod < this->rods; rod++) { tower_str += lines[rod][i]; } tower_str += "\n"; } return tower_str; }
int main() { //AStack<int> stack; LStack<int> stack; for (int i = 0; i < 10; i++) stack.push(i); cout << stack.length() << endl; while (stack.length() != 0) { cout << stack.top(); cout << stack.pop() << " "; } cout << endl; return 0; }