Beispiel #1
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;
}
Beispiel #2
0
// 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;
}