Commit bff5a3bc authored by Hans Buchmann's avatar Hans Buchmann

5-pointer/doc/unsigned-state-machine.pdf

 picture
6-cia/src/geo2d-bb.cc
6-cia/src/geo2d-vz.cc
 the cia example file
parent c249e122
......@@ -5,8 +5,35 @@
#include <iostream>
#include <cmath>
//------------------------------------------------- Point
// declaration
class Point
{
public:
Point(double x,double y); //non-default constructor no return value
~Point(); //destructor never with parameters no return value
private:
double xc; //x-coordinate
double yc; //y-coordinate
};
// implementation
Point::Point(double x,double y)
:xc(x),yc(y) //init list
//xc=x;yc=y
{
std::cout<<"constructor Point "<<xc<<","<<yc<<"\n";
}
Point::~Point()
{
std::cout<<"destructor Point "<<xc<<","<<yc<<"\n";
}
//--------------------------- use case
int main(int argc,char** args)
{
Point p(3.14,2.7); //instance of class Point
return 0;
}
},
......@@ -26,6 +26,7 @@ Point::Point(double x,double y) //x,y parameter
:xc(x),yc(y) //init list:only for construtors
//xc=x,yc=y
{
std::cout<<"constructor of Point "<<xc<<","<<yc<<"\n";
}
Point::~Point()
......@@ -37,13 +38,15 @@ Point::~Point()
int main(int argc,char**args)
{
Point p(3.1,4.7);
Point p(3.1,4.7); //definition and initialization
// | |----------- y-coordinate
// |--------------- x-coordinate
// p is an instance of the class Point
Point q(7.3,2.4);
Point q(7.3,2.4); //definition and initialization
// | |----------- y-coordinate
// |--------------- x-coordinate
// q is an instance of the class Point
return 0;
return 0;
//destructor of q
//destructor of p
}
......@@ -7,18 +7,39 @@
using Vector=std::vector<int>;
template<typename T>
T max(const T x,const T y){return (x<y)?y:x;}
struct Node
{
Node(int key):key(key){}
void insert(int k);
unsigned maxH();
void enumerate(Vector& lst);
Node* swapL();
Node* swapR();
int key;
Node* le=0;
Node* ri=0;
unsigned h =1;
Node* le=0;
Node* ri=0;
};
unsigned Node::maxH()
{
if (le)
{
if (ri) return max(le->h,ri->h);
return le->h;
}
if (ri)
{
if (le) return max(le->h,ri->h);
return ri->h;
}
return h;
}
void Node::insert(int k)
{
if (k<key)
......@@ -31,6 +52,7 @@ void Node::insert(int k)
if (ri) ri->insert(k);
else ri=new Node(k);
}
h=1+maxH();
}
void Node::enumerate(Vector& lst)
......@@ -90,7 +112,7 @@ void GraphViz::show(const Node* nd,unsigned id)
{
out<<"i"<<id<<" [label=";
if (nd==0) out<<"\"nil\" shape=none";
else out<<"\""<<nd->key<<"\"";
else out<<"\""<<nd->key<<":"<<nd->h<<"\"";
out<<"]\n";
}
......@@ -124,8 +146,9 @@ int main(int argc,char** args)
}
GraphViz gv(std::cout);
// gv.node(root);
root->le=root->le->swapR();
gv.node(root);
return 0;
// root->le=root->le->swapR();
// root=root->swapR();
gv.node(root);
Vector lst;
......
......@@ -73,4 +73,11 @@
- Strings Folie Seite 67
- Aufgaben
- ``string.cc`` exercises.pdf Aufgaben 5.1, 5.2, 5.4, 5.8, 5.9
## 12.11.2020
- 5-pointer
- Strings ``string.cc`` exercises.pdf Aufgaben 5.2, 5.4, 5.8, 5.9
- 6-cia
- Die Klasse ``Point`` Folien Seite 7
- exercises.pdf Aufgaben 1.1, 1.2, 1.3
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment