Commit 73df44ee78ac788c9a8080e527f23d31fc1884fe
1 parent
b2f035d8
Cleaned up example05
Showing
26 changed files
with
45 additions
and
49 deletions
examples05/01-template/bubblesort deleted
100755 → 0
No preview for this file type
examples05/01-template/bubblesort.o deleted
100644 → 0
No preview for this file type
examples05/01-template/makefile
| @@ -22,7 +22,7 @@ bubblesort: bubblesort.o | @@ -22,7 +22,7 @@ bubblesort: bubblesort.o | ||
| 22 | g++ -g -Wall -pedantic $^ -o $@ | 22 | g++ -g -Wall -pedantic $^ -o $@ |
| 23 | 23 | ||
| 24 | bubblesort.o: bubblesort.cpp | 24 | bubblesort.o: bubblesort.cpp |
| 25 | - g++ -g -c -Wall -pedantic $< -o $@ | 25 | + g++ -g -c -Wall $< -o $@ |
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | .PHONY: clean | 28 | .PHONY: clean |
examples05/01-template/minimum deleted
100755 → 0
No preview for this file type
examples05/01-template/minimum.cpp
| @@ -10,8 +10,6 @@ template < class T > T minimum (T x, T y) | @@ -10,8 +10,6 @@ template < class T > T minimum (T x, T y) | ||
| 10 | return y; | 10 | return y; |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | -#define min(A,B) (((A)<(B))?(A):(B)) | ||
| 14 | - | ||
| 15 | int | 13 | int |
| 16 | main () | 14 | main () |
| 17 | { | 15 | { |
| @@ -19,8 +17,4 @@ main () | @@ -19,8 +17,4 @@ main () | ||
| 19 | string a = "hello", b = "goodbye"; | 17 | string a = "hello", b = "goodbye"; |
| 20 | cout << "minimum for ints " << minimum (x, y) << endl; | 18 | cout << "minimum for ints " << minimum (x, y) << endl; |
| 21 | cout << "minimum for strings " << minimum (a, b) << endl; | 19 | cout << "minimum for strings " << minimum (a, b) << endl; |
| 22 | - | ||
| 23 | - cout << "minimum for ints " << min(x, y) << endl; | ||
| 24 | - cout << "minimum for strings " << min(a, b) << endl; | ||
| 25 | - | ||
| 26 | } | 20 | } |
examples05/01-template/minimum.o deleted
100644 → 0
No preview for this file type
examples05/01-template/swap1 deleted
100755 → 0
No preview for this file type
examples05/01-template/swap1.o deleted
100644 → 0
No preview for this file type
examples05/01-template/swap2 deleted
100755 → 0
No preview for this file type
examples05/01-template/swap2.o deleted
100644 → 0
No preview for this file type
examples05/02-vectortmpl/makefile
| 1 | all: testvector opnew | 1 | all: testvector opnew |
| 2 | 2 | ||
| 3 | testvector: testvector.o | 3 | testvector: testvector.o |
| 4 | - g++ -g -Wall -pedantic $^ -o $@ | 4 | + g++ -g -Wall $^ -o $@ |
| 5 | 5 | ||
| 6 | testvector.o: testvector.cpp vector.h | 6 | testvector.o: testvector.cpp vector.h |
| 7 | g++ -g -c -Wall -pedantic $< -o $@ | 7 | g++ -g -c -Wall -pedantic $< -o $@ |
| 8 | 8 | ||
| 9 | opnew: opnew.o | 9 | opnew: opnew.o |
| 10 | - g++ -g -Wall -pedantic $^ -o $@ | 10 | + g++ -g -Wall $^ -o $@ |
| 11 | 11 | ||
| 12 | opnew.o: opnew.cpp | 12 | opnew.o: opnew.cpp |
| 13 | g++ -g -c -Wall -pedantic $< -o $@ | 13 | g++ -g -c -Wall -pedantic $< -o $@ |
examples05/02-vectortmpl/vector.h
| @@ -3,54 +3,55 @@ | @@ -3,54 +3,55 @@ | ||
| 3 | 3 | ||
| 4 | template<class C> class vector | 4 | template<class C> class vector |
| 5 | { | 5 | { |
| 6 | - C *dane; | 6 | + C *data; |
| 7 | unsigned int size; | 7 | unsigned int size; |
| 8 | public: | 8 | public: |
| 9 | class index_out_of_range{}; | 9 | class index_out_of_range{}; |
| 10 | explicit vector (int s) | 10 | explicit vector (int s) |
| 11 | { | 11 | { |
| 12 | - dane = new C[s](); | 12 | + data = new C[s](); |
| 13 | size = s; | 13 | size = s; |
| 14 | } | 14 | } |
| 15 | + | ||
| 15 | ~vector () | 16 | ~vector () |
| 16 | { | 17 | { |
| 17 | - delete [] dane; | 18 | + delete [] data; |
| 18 | } | 19 | } |
| 19 | C& operator[] (unsigned int pos) | 20 | C& operator[] (unsigned int pos) |
| 20 | { | 21 | { |
| 21 | if (pos >= size) | 22 | if (pos >= size) |
| 22 | throw index_out_of_range(); | 23 | throw index_out_of_range(); |
| 23 | - return dane[pos]; | 24 | + return data[pos]; |
| 24 | } | 25 | } |
| 25 | C operator[] (unsigned int pos) const | 26 | C operator[] (unsigned int pos) const |
| 26 | { | 27 | { |
| 27 | if (pos >= size) | 28 | if (pos >= size) |
| 28 | throw index_out_of_range(); | 29 | throw index_out_of_range(); |
| 29 | - return dane[pos]; | 30 | + return data[pos]; |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | vector (const vector<C> & s) | 33 | vector (const vector<C> & s) |
| 33 | { | 34 | { |
| 34 | - dane = new C[s.size]; | 35 | + data = new C[s.size]; |
| 35 | size = s.size; | 36 | size = s.size; |
| 36 | try { | 37 | try { |
| 37 | for (unsigned i = 0; i < size; i++) | 38 | for (unsigned i = 0; i < size; i++) |
| 38 | - dane[i] = s.dane[i]; | 39 | + data[i] = s.data[i]; |
| 39 | } | 40 | } |
| 40 | catch(...) | 41 | catch(...) |
| 41 | { | 42 | { |
| 42 | - delete [] dane; | 43 | + delete [] data; |
| 43 | throw; | 44 | throw; |
| 44 | } | 45 | } |
| 45 | } | 46 | } |
| 46 | 47 | ||
| 47 | void swap(vector<C>& s) | 48 | void swap(vector<C>& s) |
| 48 | { | 49 | { |
| 49 | - C* t1=s.dane; | 50 | + C* t1=s.data; |
| 50 | unsigned int t2=s.size; | 51 | unsigned int t2=s.size; |
| 51 | - s.dane=dane; | 52 | + s.data=data; |
| 52 | s.size=size; | 53 | s.size=size; |
| 53 | - dane=t1; | 54 | + data=t1; |
| 54 | size=t2; | 55 | size=t2; |
| 55 | } | 56 | } |
| 56 | 57 |
examples05/03-assoctabl/assoctab.cpp
| @@ -26,9 +26,9 @@ assocTab::~assocTab () | @@ -26,9 +26,9 @@ assocTab::~assocTab () | ||
| 26 | void | 26 | void |
| 27 | assocTab::insert (const char *key, int value) | 27 | assocTab::insert (const char *key, int value) |
| 28 | { | 28 | { |
| 29 | - node *nowy = new node (key); | ||
| 30 | - nowy->next = head; | ||
| 31 | - head = nowy; | 29 | + node *newnode = new node (key); |
| 30 | + newnode->next = head; | ||
| 31 | + head = newnode; | ||
| 32 | head->val = value; | 32 | head->val = value; |
| 33 | } | 33 | } |
| 34 | 34 |
examples05/03-assoctabl/assoctab.o deleted
100644 → 0
No preview for this file type
examples05/03-assoctabl/makefile
examples05/03-assoctabl/testassoc deleted
100755 → 0
No preview for this file type
examples05/03-assoctabl/testassoc.o deleted
100644 → 0
No preview for this file type
examples05/04-assoctabl2/assoctab.cpp
| @@ -26,9 +26,9 @@ assocTab::~assocTab () | @@ -26,9 +26,9 @@ assocTab::~assocTab () | ||
| 26 | void | 26 | void |
| 27 | assocTab::insert (const char *key, int value) | 27 | assocTab::insert (const char *key, int value) |
| 28 | { | 28 | { |
| 29 | - node *nowy = new node (key); | ||
| 30 | - nowy->next = head; | ||
| 31 | - head = nowy; | 29 | + node *newnode = new node (key); |
| 30 | + newnode->next = head; | ||
| 31 | + head = newnode; | ||
| 32 | head->val = value; | 32 | head->val = value; |
| 33 | } | 33 | } |
| 34 | 34 |
examples05/04-assoctabl2/assoctab.o deleted
100644 → 0
No preview for this file type
examples05/04-assoctabl2/makefile
| 1 | testassoc: testassoc.o assoctab.o | 1 | testassoc: testassoc.o assoctab.o |
| 2 | - g++ -g -Wall -pedantic $^ -o $@ | 2 | + g++ -g -Wall $^ -o $@ |
| 3 | 3 | ||
| 4 | assoctab.o: assoctab.cpp assoctab.h vector.h | 4 | assoctab.o: assoctab.cpp assoctab.h vector.h |
| 5 | g++ -g -c -Wall -pedantic $< -o $@ | 5 | g++ -g -c -Wall -pedantic $< -o $@ |
examples05/04-assoctabl2/testassoc deleted
100755 → 0
No preview for this file type
examples05/04-assoctabl2/testassoc.o deleted
100644 → 0
No preview for this file type
examples05/04-assoctabl2/vector.h
| @@ -3,64 +3,65 @@ | @@ -3,64 +3,65 @@ | ||
| 3 | 3 | ||
| 4 | template<class C> class vector | 4 | template<class C> class vector |
| 5 | { | 5 | { |
| 6 | - C *dane; | 6 | + C *data; |
| 7 | unsigned int size; | 7 | unsigned int size; |
| 8 | public: | 8 | public: |
| 9 | class index_out_of_range{}; | 9 | class index_out_of_range{}; |
| 10 | explicit vector (int s) | 10 | explicit vector (int s) |
| 11 | { | 11 | { |
| 12 | - dane = new C[s]; | 12 | + data = new C[s]; |
| 13 | size = s; | 13 | size = s; |
| 14 | - try | ||
| 15 | - { | 14 | + try |
| 15 | + { | ||
| 16 | for (unsigned i = 0; i < size; i++) | 16 | for (unsigned i = 0; i < size; i++) |
| 17 | - dane[i] = C(); //redundant except POD types | ||
| 18 | - } | ||
| 19 | - catch (...) | ||
| 20 | - { | ||
| 21 | - delete [] dane; | ||
| 22 | - throw; | ||
| 23 | - } | 17 | + data[i] = C(); //redundant except POD types |
| 18 | + } | ||
| 19 | + catch (...) | ||
| 20 | + { | ||
| 21 | + delete [] data; | ||
| 22 | + throw; | ||
| 23 | + } | ||
| 24 | } | 24 | } |
| 25 | + | ||
| 25 | ~vector () | 26 | ~vector () |
| 26 | { | 27 | { |
| 27 | - delete [] dane; | 28 | + delete [] data; |
| 28 | } | 29 | } |
| 29 | C& operator[] (unsigned int pos) | 30 | C& operator[] (unsigned int pos) |
| 30 | { | 31 | { |
| 31 | if (pos >= size) | 32 | if (pos >= size) |
| 32 | throw index_out_of_range(); | 33 | throw index_out_of_range(); |
| 33 | - return dane[pos]; | 34 | + return data[pos]; |
| 34 | } | 35 | } |
| 35 | C operator[] (unsigned int pos) const | 36 | C operator[] (unsigned int pos) const |
| 36 | { | 37 | { |
| 37 | if (pos >= size) | 38 | if (pos >= size) |
| 38 | throw index_out_of_range(); | 39 | throw index_out_of_range(); |
| 39 | - return dane[pos]; | 40 | + return data[pos]; |
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | vector (const vector<C> & s) | 43 | vector (const vector<C> & s) |
| 43 | { | 44 | { |
| 44 | - dane = new C[s.size]; | 45 | + data = new C[s.size]; |
| 45 | size = s.size; | 46 | size = s.size; |
| 46 | try { | 47 | try { |
| 47 | for (unsigned i = 0; i < size; i++) | 48 | for (unsigned i = 0; i < size; i++) |
| 48 | - dane[i] = s.dane[i]; | 49 | + data[i] = s.data[i]; |
| 49 | } | 50 | } |
| 50 | catch(...) | 51 | catch(...) |
| 51 | { | 52 | { |
| 52 | - delete [] dane; | 53 | + delete [] data; |
| 53 | throw; | 54 | throw; |
| 54 | } | 55 | } |
| 55 | } | 56 | } |
| 56 | 57 | ||
| 57 | void swap(vector<C>& s) | 58 | void swap(vector<C>& s) |
| 58 | { | 59 | { |
| 59 | - C* t1=s.dane; | 60 | + C* t1=s.data; |
| 60 | unsigned int t2=s.size; | 61 | unsigned int t2=s.size; |
| 61 | - s.dane=dane; | 62 | + s.data=data; |
| 62 | s.size=size; | 63 | s.size=size; |
| 63 | - dane=t1; | 64 | + data=t1; |
| 64 | size=t2; | 65 | size=t2; |
| 65 | } | 66 | } |
| 66 | 67 |
examples05/05-staticmember/makefile
examples05/05-staticmember/static deleted
100755 → 0
No preview for this file type
examples05/05-staticmember/static.o deleted
100644 → 0
No preview for this file type