first commit

This commit is contained in:
Jeena Paradies 2011-04-19 11:37:05 +02:00
commit 063194f8be
349 changed files with 36508 additions and 0 deletions

View file

@ -0,0 +1,19 @@
int main () {
Counter c;
c = new Counter;
c.incr();
c.incr();
c.incr();
int x = c.value();
printInt(x);
return 0;
}
class Counter {
int val;
void incr () {val++; return;}
int value () {return val;}
}

View file

@ -0,0 +1 @@
3

View file

@ -0,0 +1,50 @@
class Node {
int elem;
Node next;
void setElem(int c) { elem = c; }
void setNext(Node n) { next = n; }
int getElem() { return elem; }
Node getNext() { return next; }
}
class Stack {
Node head;
void push(int c) {
Node newHead = new Node;
newHead.setElem(c);
newHead.setNext(head);
head = newHead;
}
boolean isEmpty() {
return head==(Node)null;
}
int top() {
return head.getElem();
}
void pop() {
head = head.getNext();
}
}
int main() {
Stack s = new Stack;
int i= 0;
while (i<10) {
s.push(i);
i++;
}
while (!s.isEmpty()) {
printInt(s.top());
s.pop();
}
return 0;
}

View file

@ -0,0 +1,10 @@
9
8
7
6
5
4
3
2
1
0

View file

@ -0,0 +1,62 @@
class Point2 {
int x;
int y;
void move (int dx, int dy) {
x = x + dx;
y = y + dy;
}
int getX () { return x; }
int getY () { return y; }
}
class Point3 extends Point2 {
int z;
void moveZ (int dz) {
z = z + dz;
}
int getZ () { return z; }
}
class Point4 extends Point3 {
int w;
void moveW (int dw) {
w = w + dw;
}
int getW () { return w; }
}
int main () {
Point2 p = new Point3;
Point3 q = new Point3;
Point4 r = new Point4;
q.move(2,4);
q.moveZ(7);
p = q;
p.move(3,5);
r.move(1,3);
r.moveZ(6);
r.moveW(2);
printInt(p.getX());
printInt(p.getY());
printInt(q.getZ());
printInt(r.getW());
return 0;
}

View file

@ -0,0 +1,4 @@
5
9
7
2

View file

@ -0,0 +1,61 @@
class Node {
int elem;
Node next;
void setElem (int e) { elem = e; }
void setNext (Node n) { next = n; }
int getElem () { return elem; }
Node getNext () { return next; }
}
class IntQueue {
Node front;
Node rear;
boolean isEmpty () { return front == (Node)null; }
void insert (int x) {
Node last = new Node;
last.setElem(x);
if (self.isEmpty())
front = last;
else
rear.setNext(last);
rear = last;
}
int first () { return front.getElem(); }
void rmFirst () {
front = front.getNext();
}
int size () {
Node n = front;
int res = 0;
while (n != (Node)null) {
n = n.getNext();
res++;
}
return res;
}
}
int f (int x) {
return x*x + 3;
}
int main () {
IntQueue q = new IntQueue;
q.insert(f(3));
q.insert(5);
q.insert(7);
printInt(q.first());
q.rmFirst();
printInt(q.size());
return 0;
}

View file

@ -0,0 +1,2 @@
12
2