Professional Documents
Culture Documents
Sol CPP 192 B
Sol CPP 192 B
) נקודות3( .'סעיף א
template <class T> class MinStack {
private:
Stack<T> stValue;
Stack<T> stMin;
T min;
public:
MinStack();
~MinStack();
bool isEmpty() const ;
bool push(const T&);
void pop(T & );
T Min();
};
) נקודות2( .'סעיף ב
MinStack() { } // Default Constructor
~MinStack() { }
) נקודוה1( .'סעיף ג
bool isEmpty() const {
return stValue.isEmpty();
}
) נקודות6( .'}סעיף ד
bool push(const T& pushValue) {
if (stValue.isEmpty()) {
stValue.push(pushValue);
stMin.push(pushValue);
min = pushValue;
return true;
}
if (stValue.push(pushValue)) {
if (pushValue < min) {
min = pushValue;
stMin.push(pushValue);
}
else
stMin.push(min);
return true;
}
else
return false;
}
) נקודות3( .'סעיף ה
void pop(T & popValue) throw(const char *) {
if (stValue.pop(popValue))
stMin.pop(min);
else
throw "pop failure";
}
) נקודה1( .'סעיף ו
T Min() {
return min;
}
1
) נקודות4( .'סעיף ז
int main() {
MinStack<int> m; //m is a min stack of ints
int arr[5] = { 1,-2,3 };
try {
cout << m.isEmpty() << endl;
m.push(arr[0]);
cout << m.isEmpty() << m.Min() << endl;
m.push(arr[1]);
cout << m.isEmpty() << m.Min() << endl;
m.pop(arr[2]);
cout << m.isEmpty() << m.Min() << endl;
m.pop(arr[3]);
cout << m.isEmpty() << m.Min() << endl;
2
) נקודות18( 3 שאלה
3
) נקודות20( C שפת4 שאלה
if (i == finish) {
fprintf(possible, "%s%08d%02d%1d%02d%02d\n",
name, courseA, points, day, start, finish);
result++;
}
}
if (fclose(possible) == EOF)
return -1;
return result;
}