int _tmain(int argc, _TCHAR* argv[]) { StackWithMin<int> stack; stack.push(3); Test("Test1", stack, 3); stack.push(4); Test("Test2", stack, 3); stack.push(2); Test("Test3", stack, 2); stack.push(3); Test("Test4", stack, 2); stack.pop(); Test("Test5", stack, 2); stack.pop(); Test("Test6", stack, 3); stack.pop(); Test("Test7", stack, 3); stack.push(0); Test("Test8", stack, 0); return 0; }
int main(int argc, const char * argv[]) { // insert code here... std::cout << "Hello, World!\n"; // Chapter 3 // try{ // push(2, 1); // push(2, 2); // push(2, 3); // //push(3, 1); // push(2, 4); // cout << pop(2) << endl; // cout << pop(2) << endl; // cout << pop(2) << endl; // cout << pop(2) << endl; // cout << pop(2) << endl; // }catch(string *s){ // cout << *s << endl; // delete s; // }catch(string s){ // cout << s << endl; // } // find stack min StackWithMin* s; s = new StackWithMin();//<class NodeWithMin>(); s->push(5); cout << s->min() << endl; s->push(3); cout << s->min() << endl; s->push(8); cout << s->min()<< endl; s->push(1); cout << s->min() << endl; // StackWithMin2* ss; // ss = new StackWithMin2<int>(); // Hanoi Tower // hanoiTower(3); // cout << "hello" << endl; // hanoiTower2(3); // Ascending stack // stack<int> * s = new stack<int>(); // s->push(1); // s->push(3); // s->push(8); // s->push(12); // s->push(5); // s->push(10); // stack<int>* new_s = stackSort(s); // while(!new_s->empty()){ // cout << new_s->top() << endl; // new_s->pop(); // } return 0; }
int main(int argc, char **argv) { StackWithMin s; s.push(100); s.push(50); s.push(70); s.push(90); s.push(30); printf("min = %d\n", s.min()); printf("%d\n", s.pop()); printf("min = %d\n", s.min()); printf("%d\n", s.pop()); printf("min = %d\n", s.min()); printf("%d\n", s.pop()); printf("min = %d\n", s.min()); printf("%d\n", s.pop()); printf("min = %d\n", s.min()); printf("%d\n", s.pop()); printf("min = %d\n", s.min()); return 0; }
int main(int argc, const char * argv[]) { StackWithMin<int> s; s.push(5); s.push(2); s.push(3); s.push(1); cout<<s.min()<<endl; s.pop(); cout<<s.min()<<endl; return 0; }
int main(){ //cout<<MIN_INT<<endl; StackWithMin mystack;//StackWithMin mystack; for(int i=0; i<20; ++i) mystack.push(i); cout<<mystack.min()<<" "<<mystack.top()<<endl; mystack.push(-100); mystack.push(-100); cout<<mystack.min()<<" "<<mystack.top()<<endl; mystack.pop(); cout<<mystack.min()<<" "<<mystack.top()<<endl; return 0; }
int main() { cout<<"Program running:"<<endl; StackWithMin sMin; sMin.push(5); sMin.push(3); sMin.push(6); sMin.push(2); sMin.push(1); int temp = 0; cout<<sMin.minV()<<"\t"<<endl; sMin.pop(temp); cout<<sMin.minV()<<"\t"<<endl; sMin.pop(temp); cout<<sMin.minV()<<"\t"<<endl; sMin.pop(temp); cout<<sMin.minV()<<"\t"<<endl; sMin.pop(temp); cout<<sMin.minV()<<"\t"<<endl; sMin.pop(temp); cout<<sMin.minV()<<"\t"<<endl; return 0; }
int main(int argc, char* argv []) { StackWithMin stack; auto list = { 3, 5, 1, 5, 2, 4 }; for (int n : list) stack.push(n); while (!stack.empty()) { cout << "v: " << stack.top() << " min: " << stack.min() << endl; stack.pop(); } return 0; }
int main() { StackWithMin newStack; for(int i = 0; i < 40; i++) { newStack.push(rand() % 100 + 1); } for(int i = 0; i < 28; i++) { newStack.pop(); } cout << newStack.minimum() << " is the min." << endl; }
int main(int argc, char const *argv[]) { StackWithMin<int> ss; ss.push(4); ss.push(9); ss.push(1); ss.push(11); ss.push(6); cout << "min:" << ss.min() << endl; cout << "top:" << ss.top() << endl; ss.pop(); cout << "min:" << ss.min() << endl; cout << "top:" << ss.top() << endl; if (ss.empty() == true) { cout << "the stack is empty!" <<endl; } else { cout << "the stack is not empty!" <<endl; cout << "the stack's size is:" << ss.size() <<endl; } return 0; }
int main() { StackWithMin stk; for (int i = 0; i < 10; i++) { int value = rand() % 150; cout << "push : " << value << endl; stk.push(value); } cout << "Push 10 Elements and current min is : " << stk.min() << endl << endl; for (int i = 0; i < 5; i++) { int value = stk.top(); cout << "pop : " << value << endl; stk.pop(); } cout << "After pop 5 Elements, current min is : " << stk.min() << endl; system("pause"); return 0; }
int main(int argc,char*argv[]){ StackWithMin swm; StackWithMin2 swm2; cout << "size: " << sizeof(swm) << " " << sizeof(swm2) << endl; srand(time(NULL)); int m = rand()%10; int n = rand()%10; cout << "push " << m << " times" << endl; for(int i=0;i<m;++i){ int tmp = rand()%50; swm.push(tmp); swm2.push(tmp); cout << tmp << " "; } cout << endl << "size: " << sizeof(swm) << " " << sizeof(swm2) << endl; cout << "pop " << n << " times" << endl; for(int i=0;i<n;++i){ cout << "mini: " << swm.min() << endl; cout << "mini2: " << swm2.min() << endl; swm.pop(); swm2.pop(); } return 0; }
void verifySolution() { StackWithMin<int> stack; stack.push(5); CPPUNIT_ASSERT(stack.top() == 5); CPPUNIT_ASSERT(stack.min() == 5); stack.push(4); CPPUNIT_ASSERT(stack.top() == 4); CPPUNIT_ASSERT(stack.min() == 4); stack.push(5); CPPUNIT_ASSERT(stack.top() == 5); CPPUNIT_ASSERT(stack.min() == 4); stack.push(2); CPPUNIT_ASSERT(stack.top() == 2); CPPUNIT_ASSERT(stack.min() == 2); stack.pop(); CPPUNIT_ASSERT(stack.top() == 5); CPPUNIT_ASSERT(stack.min() == 4); stack.push(3); CPPUNIT_ASSERT(stack.top() == 3); CPPUNIT_ASSERT(stack.min() == 3); stack.push(4); CPPUNIT_ASSERT(stack.top() == 4); CPPUNIT_ASSERT(stack.min() == 3); stack.push(1); CPPUNIT_ASSERT(stack.top() == 1); CPPUNIT_ASSERT(stack.min() == 1); stack.pop(); CPPUNIT_ASSERT(stack.top() == 4); CPPUNIT_ASSERT(stack.min() == 3); stack.pop(); CPPUNIT_ASSERT(stack.top() == 3); CPPUNIT_ASSERT(stack.min() == 3); stack.pop(); CPPUNIT_ASSERT(stack.top() == 5); CPPUNIT_ASSERT(stack.min() == 4); stack.pop(); CPPUNIT_ASSERT(stack.top() == 4); CPPUNIT_ASSERT(stack.min() == 4); stack.pop(); CPPUNIT_ASSERT(stack.top() == 5); CPPUNIT_ASSERT(stack.min() == 5); stack.push(2); stack.push(3); stack.push(2); stack.push(3); CPPUNIT_ASSERT(stack.top() == 3); CPPUNIT_ASSERT(stack.min() == 2); stack.pop(); CPPUNIT_ASSERT(stack.top() == 2); CPPUNIT_ASSERT(stack.min() == 2); stack.pop(); CPPUNIT_ASSERT(stack.top() == 3); CPPUNIT_ASSERT(stack.min() == 2); stack.pop(); CPPUNIT_ASSERT(stack.top() == 2); CPPUNIT_ASSERT(stack.min() == 2); stack.pop(); CPPUNIT_ASSERT(stack.top() == 5); CPPUNIT_ASSERT(stack.min() == 5); auto start = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now(); auto diff = end - start; std::cout << std::endl; std::cout << "Microseconds: " << std::chrono::duration <double,std::micro> (diff).count() << " us" << std::endl; }