CSE 2221 Final: CSE 2221 Stack Notes

110 views2 pages

Document Summary

Standard has contracts for three methods: method (cid:862)clear(cid:863, method (cid:862)newinstance(cid:863, method (cid:862)transferfrom(cid:863) Stackkernel has contracts for three methods: method (cid:862)push(cid:863, method (cid:862)pop(cid:863, method (cid:862)length(cid:863) Stack has a contract for three other methods: method (cid:862)top(cid:863, method (cid:862)replacetop(cid:863, method (cid:862)flip(cid:863) The value of a stack variable is modeled as a string of entries of type t. Formally: type stack is modeled by string of t. Method (cid:862)push(cid:863) void push(t x: adds x at the top (left end) of this, aliases: reference x, updates: this. T pop(: removes and returns the entry at the top (left end) of this, updates: this, requires: this /= < > Method (cid:862)length(cid:863) int length(: reports the length of this. T top(: returns the entry at the top (left end) of this, aliases: reference returned by top, requires: this /= < > T replacetop(t x: replaces the top of this with x, and returns the old top, aliases: reference x, updates: this, requires: this /= < >