int main() { SimpleStack s; char c; printf("testing push/pop..."); if (!s.push('a')) goto fail; if (!s.push('b')) goto fail; if (!s.push('c')) goto fail; if (!s.pop(&c) || c != 'c') goto fail; if (!s.pop(&c) || c != 'b') goto fail; if (!s.pop(&c) || c != 'a') goto fail; printf("[ok]\n"); printf("testing empty..."); if (!s.empty()) goto fail; s.push('a'); if (s.empty()) goto fail; printf("[ok]\n"); return 0; fail: printf("[failed]\n"); return -1; }
int main() { // ein Stack für 100 int-Zahlen SimpleStack<int,100> einIntStack; // Stack füllen int i = 100; while(!einIntStack.full()) einIntStack.push(i++); cout << "Anzahl : " << einIntStack.size() << endl; // oberstes Element anzeigen cout << "oberstes Element: " << einIntStack.top() << endl; cout << "alle Elemente entnehmen und anzeigen: " << endl; while(!einIntStack.empty()) { i = einIntStack.top(); einIntStack.pop(); cout << i << '\t'; } cout << endl; }