Thursday, September 1, 2011

lecture 2 notes


HW #1: Make a C++ Stack class. It should hold ints. We should have the following methods: empty, full, push, pop, top. It should be based on an array.

class Stack
{
int A[100];
int Top;
public:
Stack() { }
void push(int x) { A[Top++] = x; }
int pop() { return A[--Top]; }
int top() { return A[Top-1]; }
bool isEmpty() { ... }
bool isFull() { ... }
}

main()
{
Stack a;
a.push(6);
...
return 0;
}

Person p   =   new Person("John");
// is the same as
Person p;
p   =   new Person("John");

No comments:

Post a Comment