Systemnahe Programmierung in C: Dynamisches Binden |
1class StackInterface {
2
3public:
4
5 virtual void push(int i) = 0;
6 virtual void pop() = 0;
7 virtual int top() = 0;
8 virtual int isEmpty() = 0;
9};
10
11class StackAsArry : public StackInterface {
12
13private:
14
15 int a[20];
16 unsigned int topPtr;
17
18public:
19 void push(int i) {
20 // ...
21 }
22
23 // ...
24};
25
26class StackAsLinkedList : public StackInterface {
27 // ...
28};
|
1#include "Stack6.cc"
2
3int main(void)
4{
5 Stack * s1 = new StackAsArray();
6 Stack * s2 = new StackLinkedList();
7
8 s1->push(...);
9
10 ... s1->top() ...;
11
12 s2->pop();
13
14 ... ( s2->isEmpty() )
15
16 s2->push(...);
17
18 s1->pop();
19
20}
|
|
Letzte Änderung: 11.01.2007 | © Prof. Dr. Uwe Schmidt |