int main(){ LinkedListStack<int> stack = LinkedListStack<int>(); stack.push(1); stack.push(2); stack.push(3); stack.push(4); stack.push(5); stack.push(6); stack.push(7); Invierte(stack, 3); return 0; }
void Invierte(LinkedListStack <T> stack, const int &positions){ //tengo que poner el type aqui ya????? Se puede hacer con listas?? T *intermedia = new T[positions]; int i = 0; while (!stack.empty() && i<positions){ intermedia[i] = stack.top(); stack.pop(); i++; } for (int j = 0 ; j <i; j++){ stack.push(intermedia[j]); } delete[] intermedia; }
// Test input: // to be or not to - be - - that - - - is // run with: cat data/tobe.txt | ./bin/stack int main(int argc, char *argv[]) { LinkedListStack<std::string> stackList; ResizingArrayStack<std::string> stackArray; string lineInput; while (cin >> lineInput) { string *item = new string(lineInput); if(item->compare("-")) { stackList.push(item); stackArray.push(item); } else if(!stackList.isEmpty()) { cout << *stackList.pop() << " "; cout << *stackArray.pop() << " "; } } cout << endl << "(" << stackList.size() << " left on stackList)" << endl; cout << "(" << stackArray.size() << " left on stackArray)" << endl; return 0; }