Commit 73df44ee78ac788c9a8080e527f23d31fc1884fe

Authored by Grzegorz Jabłoński
1 parent b2f035d8

Cleaned up example05

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 22 g++ -g -Wall -pedantic $^ -o $@
23 23  
24 24 bubblesort.o: bubblesort.cpp
25   - g++ -g -c -Wall -pedantic $< -o $@
  25 + g++ -g -c -Wall $< -o $@
26 26  
27 27  
28 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 &lt; class T &gt; T minimum (T x, T y)
10 10 return y;
11 11 }
12 12  
13   -#define min(A,B) (((A)<(B))?(A):(B))
14   -
15 13 int
16 14 main ()
17 15 {
... ... @@ -19,8 +17,4 @@ main ()
19 17 string a = "hello", b = "goodbye";
20 18 cout << "minimum for ints " << minimum (x, y) << endl;
21 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 1 all: testvector opnew
2 2  
3 3 testvector: testvector.o
4   - g++ -g -Wall -pedantic $^ -o $@
  4 + g++ -g -Wall $^ -o $@
5 5  
6 6 testvector.o: testvector.cpp vector.h
7 7 g++ -g -c -Wall -pedantic $< -o $@
8 8  
9 9 opnew: opnew.o
10   - g++ -g -Wall -pedantic $^ -o $@
  10 + g++ -g -Wall $^ -o $@
11 11  
12 12 opnew.o: opnew.cpp
13 13 g++ -g -c -Wall -pedantic $< -o $@
... ...
examples05/02-vectortmpl/vector.h
... ... @@ -3,54 +3,55 @@
3 3  
4 4 template<class C> class vector
5 5 {
6   - C *dane;
  6 + C *data;
7 7 unsigned int size;
8 8 public:
9 9 class index_out_of_range{};
10 10 explicit vector (int s)
11 11 {
12   - dane = new C[s]();
  12 + data = new C[s]();
13 13 size = s;
14 14 }
  15 +
15 16 ~vector ()
16 17 {
17   - delete [] dane;
  18 + delete [] data;
18 19 }
19 20 C& operator[] (unsigned int pos)
20 21 {
21 22 if (pos >= size)
22 23 throw index_out_of_range();
23   - return dane[pos];
  24 + return data[pos];
24 25 }
25 26 C operator[] (unsigned int pos) const
26 27 {
27 28 if (pos >= size)
28 29 throw index_out_of_range();
29   - return dane[pos];
  30 + return data[pos];
30 31 }
31 32  
32 33 vector (const vector<C> & s)
33 34 {
34   - dane = new C[s.size];
  35 + data = new C[s.size];
35 36 size = s.size;
36 37 try {
37 38 for (unsigned i = 0; i < size; i++)
38   - dane[i] = s.dane[i];
  39 + data[i] = s.data[i];
39 40 }
40 41 catch(...)
41 42 {
42   - delete [] dane;
  43 + delete [] data;
43 44 throw;
44 45 }
45 46 }
46 47  
47 48 void swap(vector<C>& s)
48 49 {
49   - C* t1=s.dane;
  50 + C* t1=s.data;
50 51 unsigned int t2=s.size;
51   - s.dane=dane;
  52 + s.data=data;
52 53 s.size=size;
53   - dane=t1;
  54 + data=t1;
54 55 size=t2;
55 56 }
56 57  
... ...
examples05/03-assoctabl/assoctab.cpp
... ... @@ -26,9 +26,9 @@ assocTab::~assocTab ()
26 26 void
27 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 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
1 1 testassoc: testassoc.o assoctab.o
2   - g++ -g -Wall -pedantic $^ -o $@
  2 + g++ -g -Wall $^ -o $@
3 3  
4 4 assoctab.o: assoctab.cpp assoctab.h
5 5 g++ -g -c -Wall -pedantic $< -o $@
... ...
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 26 void
27 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 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 1 testassoc: testassoc.o assoctab.o
2   - g++ -g -Wall -pedantic $^ -o $@
  2 + g++ -g -Wall $^ -o $@
3 3  
4 4 assoctab.o: assoctab.cpp assoctab.h vector.h
5 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 3  
4 4 template<class C> class vector
5 5 {
6   - C *dane;
  6 + C *data;
7 7 unsigned int size;
8 8 public:
9 9 class index_out_of_range{};
10 10 explicit vector (int s)
11 11 {
12   - dane = new C[s];
  12 + data = new C[s];
13 13 size = s;
14   - try
15   - {
  14 + try
  15 + {
16 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 26 ~vector ()
26 27 {
27   - delete [] dane;
  28 + delete [] data;
28 29 }
29 30 C& operator[] (unsigned int pos)
30 31 {
31 32 if (pos >= size)
32 33 throw index_out_of_range();
33   - return dane[pos];
  34 + return data[pos];
34 35 }
35 36 C operator[] (unsigned int pos) const
36 37 {
37 38 if (pos >= size)
38 39 throw index_out_of_range();
39   - return dane[pos];
  40 + return data[pos];
40 41 }
41 42  
42 43 vector (const vector<C> & s)
43 44 {
44   - dane = new C[s.size];
  45 + data = new C[s.size];
45 46 size = s.size;
46 47 try {
47 48 for (unsigned i = 0; i < size; i++)
48   - dane[i] = s.dane[i];
  49 + data[i] = s.data[i];
49 50 }
50 51 catch(...)
51 52 {
52   - delete [] dane;
  53 + delete [] data;
53 54 throw;
54 55 }
55 56 }
56 57  
57 58 void swap(vector<C>& s)
58 59 {
59   - C* t1=s.dane;
  60 + C* t1=s.data;
60 61 unsigned int t2=s.size;
61   - s.dane=dane;
  62 + s.data=data;
62 63 s.size=size;
63   - dane=t1;
  64 + data=t1;
64 65 size=t2;
65 66 }
66 67  
... ...
examples05/05-staticmember/makefile
1 1 static: static.o
2   - g++ -g -Wall -pedantic $^ -o $@
  2 + g++ -g -Wall $^ -o $@
3 3  
4 4 static.o: static.cpp
5 5 g++ -g -c -Wall -pedantic $< -o $@
... ...
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