From a0546991f4c3369e1d95e720d133bf315bc4cd79 Mon Sep 17 00:00:00 2001 From: Peter Gerwinski <peter@cassini.intern> Date: Thu, 3 Dec 2015 16:24:49 +0100 Subject: [PATCH] Vorlesung 26.11.2015 --- 20151126/fifo-1.c | 67 +++++++++++++++++ 20151126/fifo-2.c | 73 +++++++++++++++++++ 20151126/fifo-3.c | 70 ++++++++++++++++++ 20151126/fifo-4.c | 62 ++++++++++++++++ 20151126/orzol/Text-Grafik-Bibliothek-1.c | 57 +++++++++++++++ 20151126/orzol/Text-Grafik-Bibliothek-2.c | 62 ++++++++++++++++ 20151126/orzol/Text-Grafik-Bibliothek-20x15.c | 56 ++++++++++++++ 20151126/orzol/Text-Grafik-Bibliothek-20x15.h | 8 ++ 20151126/orzol/Text-Grafik-Bibliothek-3.c | 62 ++++++++++++++++ 20151126/orzol/Text-Grafik-Bibliothek-pg.c | 56 ++++++++++++++ 20151126/orzol/Text-Grafik-Bibliothek.c | 56 ++++++++++++++ 20151126/orzol/Text-Grafik-Bibliothek.h | 8 ++ 20151126/orzol/blink.sh | 1 + 20151126/orzol/stack.c | 62 ++++++++++++++++ 20151126/orzol/stack.h | 9 +++ 20151126/orzol/test-1.c | 10 +++ 20151126/orzol/test-2.c | 10 +++ 20151126/orzol/test-3.c | 10 +++ 20151126/orzol/test-4.c | 23 ++++++ 20151126/orzol/test-5.c | 23 ++++++ 20151126/orzol/test.c | 22 ++++++ 20151126/stack-0.c | 12 +++ 20151126/stack-1.c | 21 ++++++ 20151126/stack-2.c | 27 +++++++ 20151126/stack-3.c | 37 ++++++++++ 20151126/stack-4.c | 37 ++++++++++ 20151126/stack-5.c | 40 ++++++++++ 20151126/stack-6.c | 43 +++++++++++ 20151126/stack-7.c | 40 ++++++++++ 20151126/stack-8.c | 67 +++++++++++++++++ 30 files changed, 1131 insertions(+) create mode 100644 20151126/fifo-1.c create mode 100644 20151126/fifo-2.c create mode 100644 20151126/fifo-3.c create mode 100644 20151126/fifo-4.c create mode 100644 20151126/orzol/Text-Grafik-Bibliothek-1.c create mode 100644 20151126/orzol/Text-Grafik-Bibliothek-2.c create mode 100644 20151126/orzol/Text-Grafik-Bibliothek-20x15.c create mode 100644 20151126/orzol/Text-Grafik-Bibliothek-20x15.h create mode 100644 20151126/orzol/Text-Grafik-Bibliothek-3.c create mode 100644 20151126/orzol/Text-Grafik-Bibliothek-pg.c create mode 100644 20151126/orzol/Text-Grafik-Bibliothek.c create mode 100644 20151126/orzol/Text-Grafik-Bibliothek.h create mode 100644 20151126/orzol/blink.sh create mode 100644 20151126/orzol/stack.c create mode 100644 20151126/orzol/stack.h create mode 100644 20151126/orzol/test-1.c create mode 100644 20151126/orzol/test-2.c create mode 100644 20151126/orzol/test-3.c create mode 100644 20151126/orzol/test-4.c create mode 100644 20151126/orzol/test-5.c create mode 100644 20151126/orzol/test.c create mode 100644 20151126/stack-0.c create mode 100644 20151126/stack-1.c create mode 100644 20151126/stack-2.c create mode 100644 20151126/stack-3.c create mode 100644 20151126/stack-4.c create mode 100644 20151126/stack-5.c create mode 100644 20151126/stack-6.c create mode 100644 20151126/stack-7.c create mode 100644 20151126/stack-8.c diff --git a/20151126/fifo-1.c b/20151126/fifo-1.c new file mode 100644 index 0000000..0efa572 --- /dev/null +++ b/20151126/fifo-1.c @@ -0,0 +1,67 @@ +#include <stdio.h> +#include <stdlib.h> + +#define FIFO_SIZE 42 + +int fifo[FIFO_SIZE]; +int fifo_pointer = 0; + +void fatal_error (char *msg) +{ + fprintf (stderr, "%s\n", msg); + exit (1); +} + +void push (int x) +{ + if (fifo_pointer < 0 || fifo_pointer >= FIFO_SIZE) + fatal_error ("fifo overflow"); + else + fifo[fifo_pointer++] = x; +} + +int pop (void) +{ + if (fifo_pointer < 1 || fifo_pointer > FIFO_SIZE) + { + fatal_error ("fifo underflow"); + return 0; + } + else + return fifo[--fifo_pointer]; +} + +void dump (void) +{ + if (fifo_pointer < 0) + fatal_error ("fifo underflow"); + else if (fifo_pointer >= FIFO_SIZE) + fatal_error ("fifo overflow"); + else if (fifo_pointer == 0) + printf ("fifo is empty\n"); + else + { + printf ("fifo:"); + for (int i = 0; i < fifo_pointer; i++) + printf (" %d", fifo[i]); + printf ("\n"); + } +} + +int main (void) +{ + dump (); + push (7); + dump (); + push (13); + dump (); + push (42); + dump (); + printf ("%d\n", pop ()); /* 42 */ + dump (); + printf ("%d\n", pop ()); /* 13 */ + dump (); + printf ("%d\n", pop ()); /* 7 */ + dump (); + return 0; +} diff --git a/20151126/fifo-2.c b/20151126/fifo-2.c new file mode 100644 index 0000000..7dcc39b --- /dev/null +++ b/20151126/fifo-2.c @@ -0,0 +1,73 @@ +#include <stdio.h> +#include <stdlib.h> + +#define FIFO_SIZE 42 + +int fifo[FIFO_SIZE]; +int fifo_pointer = 0; + +void fatal_error (char *msg) +{ + fprintf (stderr, "%s\n", msg); + exit (1); +} + +void push (int x) +{ + if (fifo_pointer < 0 || fifo_pointer >= FIFO_SIZE) + fatal_error ("fifo overflow"); + else + fifo[fifo_pointer++] = x; +} + +int pop (void) +{ + if (fifo_pointer < 1 || fifo_pointer > FIFO_SIZE) + { + fatal_error ("fifo underflow"); + return 0; + } + else + { + int value = fifo[0]; + for (int i = 1; i < fifo_pointer; i++) + fifo[i - 1] = fifo[i]; + fifo_pointer--; + return value; + } +} + +void dump (void) +{ + if (fifo_pointer < 0) + fatal_error ("fifo underflow"); + else if (fifo_pointer >= FIFO_SIZE) + fatal_error ("fifo overflow"); + else if (fifo_pointer == 0) + printf ("fifo is empty\n"); + else + { + printf ("fifo:"); + for (int i = 0; i < fifo_pointer; i++) + printf (" %d", fifo[i]); + printf ("\n"); + } +} + +int main (void) +{ + dump (); + push (7); + dump (); + push (13); + dump (); + push (42); + dump (); + printf ("%d\n", pop ()); /* 42 */ + dump (); + printf ("%d\n", pop ()); /* 13 */ + dump (); + printf ("%d\n", pop ()); /* 7 */ + dump (); + return 0; +} diff --git a/20151126/fifo-3.c b/20151126/fifo-3.c new file mode 100644 index 0000000..df62cbb --- /dev/null +++ b/20151126/fifo-3.c @@ -0,0 +1,70 @@ +#include <stdio.h> +#include <stdlib.h> + +#define FIFO_SIZE 42 + +int fifo[FIFO_SIZE]; +int fifo_read_pointer = 0; +int fifo_write_pointer = 0; + +void fatal_error (char *msg) +{ + fprintf (stderr, "%s\n", msg); + exit (1); +} + +void push (int x) +{ + if (fifo_write_pointer < 0 || fifo_write_pointer >= FIFO_SIZE) + fatal_error ("fifo overflow"); + else + fifo[fifo_write_pointer++] = x; +} + +int pop (void) +{ + if (fifo_read_pointer < 0 || fifo_read_pointer >= fifo_write_pointer) + { + fatal_error ("fifo underflow"); + return 0; + } + else + return fifo[fifo_read_pointer++]; +} + +void dump (void) +{ +/* + if (fifo_pointer < 0) + fatal_error ("fifo underflow"); + else if (fifo_pointer >= FIFO_SIZE) + fatal_error ("fifo overflow"); + else if (fifo_pointer == 0) + printf ("fifo is empty\n"); + else + { + printf ("fifo:"); + for (int i = 0; i < fifo_pointer; i++) + printf (" %d", fifo[i]); + printf ("\n"); + } +*/ +} + +int main (void) +{ + dump (); + push (7); + dump (); + push (13); + dump (); + push (42); + dump (); + printf ("%d\n", pop ()); /* 42 */ + dump (); + printf ("%d\n", pop ()); /* 13 */ + dump (); + printf ("%d\n", pop ()); /* 7 */ + dump (); + return 0; +} diff --git a/20151126/fifo-4.c b/20151126/fifo-4.c new file mode 100644 index 0000000..d4efc40 --- /dev/null +++ b/20151126/fifo-4.c @@ -0,0 +1,62 @@ +#include <stdio.h> +#include <stdlib.h> + +#define FIFO_SIZE 42 + +int fifo[FIFO_SIZE]; +int fifo_read_pointer = 0; +int fifo_write_pointer = 0; + +void fatal_error (char *msg) +{ + fprintf (stderr, "%s\n", msg); + exit (1); +} + +void push (int x) +{ + if (fifo_write_pointer < 0 || fifo_write_pointer >= FIFO_SIZE) + fatal_error ("push: fifo inconsistence"); + else + { + fifo[fifo_write_pointer++] = x; + if (fifo_write_pointer >= FIFO_SIZE) + fifo_write_pointer = 0; + if (fifo_write_pointer == fifo_read_pointer) + fatal_error ("fifo overflow"); + } +} + +int pop (void) +{ + if (fifo_read_pointer < 0 || fifo_read_pointer >= FIFO_SIZE) + { + fatal_error ("pop: fifo inconsistence"); + return 0; + } + else if (fifo_read_pointer == fifo_write_pointer) + { + fatal_error ("fifo underflow"); + return 0; + } + else + { + int value = fifo[fifo_read_pointer++]; + if (fifo_read_pointer >= FIFO_SIZE) + fifo_read_pointer = 0; + return value; + } +} + +int main (void) +{ + int value = 42; + for (int i = 0; i < 7; i++) + { + for (int j = 0; j < 10; j++) + push (value++); + for (int j = 0; j < 10; j++) + printf ("%d\n", pop ()); + } + return 0; +} diff --git a/20151126/orzol/Text-Grafik-Bibliothek-1.c b/20151126/orzol/Text-Grafik-Bibliothek-1.c new file mode 100644 index 0000000..3cb47ec --- /dev/null +++ b/20151126/orzol/Text-Grafik-Bibliothek-1.c @@ -0,0 +1,57 @@ +#include "Text-Grafik-Bibliothek-20x15.h" +#include <stdio.h> +#include "stack.h" + +char screen[WIDTH][HEIGHT]; + +//Setze alle Einträge in display auf c +void clear (char c) +{ + for (int i=0;i<WIDTH;i++) + { + for (int j=0;j<HEIGHT;j++) + { + screen[i][j]=c; + } + } +} + +//setze display [x][y] auf c +void putPoint (int x, int y, char c) +{ + screen[x][y]=c; +} + +//Gebe display[x][y] zurück +char getPoint (int x, int y) +{ + char c=screen[x][y]; + return c; +} + +//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus +void fill (int x, int y, char c, char o) +{ + if (getPoint(x,y)==o) + { + putPoint(x,y,c); + push(x+1,y); + push(x-1,y); + push(x,y+1); + push(x,y-1); + } +} + +//Gib display aus +void display (void) +{ + for (int i=0;i<HEIGHT;i++) + { + for (int j=0;j<WIDTH;j++) + { + printf("%c",screen[j][i]); + } + printf("\n"); + } +} + diff --git a/20151126/orzol/Text-Grafik-Bibliothek-2.c b/20151126/orzol/Text-Grafik-Bibliothek-2.c new file mode 100644 index 0000000..54df172 --- /dev/null +++ b/20151126/orzol/Text-Grafik-Bibliothek-2.c @@ -0,0 +1,62 @@ +#include "Text-Grafik-Bibliothek-20x15.h" +#include <stdio.h> +#include "stack.h" + +char screen[WIDTH][HEIGHT]; + +//Setze alle Einträge in display auf c +void clear (char c) +{ + for (int i=0;i<WIDTH;i++) + { + for (int j=0;j<HEIGHT;j++) + { + screen[i][j]=c; + } + } +} + +//setze display [x][y] auf c +void putPoint (int x, int y, char c) +{ + screen[x][y]=c; +} + +//Gebe display[x][y] zurück +char getPoint (int x, int y) +{ + char c=screen[x][y]; + return c; +} + +//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus +void fill (int x, int y, char c, char o) +{ + push (x, y); + while (!stack_empty ()) + { + pop (&x, &y); + if (getPoint (x, y) == o) + { + putPoint (x, y, c); + push (x + 1, y); + push (x - 1, y); + push (x, y + 1); + push (x, y - 1); + } + } +} + +//Gib display aus +void display (void) +{ + for (int i=0;i<HEIGHT;i++) + { + for (int j=0;j<WIDTH;j++) + { + printf("%c",screen[j][i]); + } + printf("\n"); + } +} + diff --git a/20151126/orzol/Text-Grafik-Bibliothek-20x15.c b/20151126/orzol/Text-Grafik-Bibliothek-20x15.c new file mode 100644 index 0000000..e721fe2 --- /dev/null +++ b/20151126/orzol/Text-Grafik-Bibliothek-20x15.c @@ -0,0 +1,56 @@ +#include "Text-Grafik-Bibliothek-20x15.h" +#include <stdio.h> + +char screen[WIDTH][HEIGHT]; + +//Setze alle Einträge in display auf c +void clear (char c) +{ + for (int i=0;i<WIDTH;i++) + { + for (int j=0;j<HEIGHT;j++) + { + screen[i][j]=c; + } + } +} + +//setze display [x][y] auf c +void putPoint (int x, int y, char c) +{ + screen[x][y]=c; +} + +//Gebe display[x][y] zurück +char getPoint (int x, int y) +{ + char c=screen[x][y]; + return c; +} + +//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus +void fill (int x, int y, char c, char o) +{ + if (getPoint(x,y)==o) + { + putPoint(x,y,c); + fill(x+1,y,c,o); + fill(x-1,y,c,o); + fill(x,y+1,c,o); + fill(x,y-1,c,o); + } +} + +//Gib display aus +void display (void) +{ + for (int i=0;i<HEIGHT;i++) + { + for (int j=0;j<WIDTH;j++) + { + printf("%c",screen[j][i]); + } + printf("\n"); + } +} + diff --git a/20151126/orzol/Text-Grafik-Bibliothek-20x15.h b/20151126/orzol/Text-Grafik-Bibliothek-20x15.h new file mode 100644 index 0000000..39486cb --- /dev/null +++ b/20151126/orzol/Text-Grafik-Bibliothek-20x15.h @@ -0,0 +1,8 @@ +#define HEIGHT 20 +#define WIDTH 15 + +extern void clear(char c); +extern void fill(int x, int y, char c, char o); +extern void putPoint(int x, int y, char c); +extern char getPoint(int x, int y); +extern void display(void); diff --git a/20151126/orzol/Text-Grafik-Bibliothek-3.c b/20151126/orzol/Text-Grafik-Bibliothek-3.c new file mode 100644 index 0000000..9353e6a --- /dev/null +++ b/20151126/orzol/Text-Grafik-Bibliothek-3.c @@ -0,0 +1,62 @@ +#include "Text-Grafik-Bibliothek-20x15.h" +#include <stdio.h> +#include "stack.h" + +char screen[WIDTH][HEIGHT]; + +//Setze alle Einträge in display auf c +void clear (char c) +{ + for (int i=0;i<WIDTH;i++) + { + for (int j=0;j<HEIGHT;j++) + { + screen[i][j]=c; + } + } +} + +//setze display [x][y] auf c +void putPoint (int x, int y, char c) +{ + screen[x][y]=c; +} + +//Gebe display[x][y] zurück +char getPoint (int x, int y) +{ + char c=screen[x][y]; + return c; +} + +//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus +void fill (int x, int y, char c, char o) +{ + push (x, y); + while (!stack_empty ()) + { + pop (&x, &y); + if (getPoint (x, y) == o) + { + putPoint (x, y, c++); + push (x + 1, y); + push (x - 1, y); + push (x, y + 1); + push (x, y - 1); + } + } +} + +//Gib display aus +void display (void) +{ + for (int i=0;i<HEIGHT;i++) + { + for (int j=0;j<WIDTH;j++) + { + printf("%c",screen[j][i]); + } + printf("\n"); + } +} + diff --git a/20151126/orzol/Text-Grafik-Bibliothek-pg.c b/20151126/orzol/Text-Grafik-Bibliothek-pg.c new file mode 100644 index 0000000..ec61ddc --- /dev/null +++ b/20151126/orzol/Text-Grafik-Bibliothek-pg.c @@ -0,0 +1,56 @@ +#include "Text-Grafik-Bibliothek.h" +#include <stdio.h> + +char screen[WIDTH][HEIGHT]; + +//Setze alle Einträge in display auf c +void clear (char c) +{ + for (int i=0;i<WIDTH;i++) + { + for (int j=0;j<HEIGHT;j++) + { + screen[i][j]=c; + } + } +} + +//setze display [x][y] auf c +void putPoint (int x, int y, char c) +{ + screen[x][y]=c; +} + +//Gebe display[x][y] zurück +char getPoint (int x, int y) +{ + char c=screen[x][y]; + return c; +} + +//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus +void fill (int x, int y, char c, char o) +{ + if (getPoint(x,y)==o) + { + putPoint(x,y,c); + fill(x+1,y,c,o); + fill(x-1,y,c,o); + fill(x,y+1,c,o); + fill(x,y-1,c,o); + } +} + +//Gib display aus +void display (void) +{ + for (int i=0;i<HEIGHT;i++) + { + for (int j=0;j<WIDTH;j++) + { + printf("%c",screen[j][i]); + } + printf("\n"); + } +} + diff --git a/20151126/orzol/Text-Grafik-Bibliothek.c b/20151126/orzol/Text-Grafik-Bibliothek.c new file mode 100644 index 0000000..476ed45 --- /dev/null +++ b/20151126/orzol/Text-Grafik-Bibliothek.c @@ -0,0 +1,56 @@ +#include "Text-Grafik-Bibliothek.h" +#include <stdio.h> + +char screen[WIDTH][HEIGHT]; + +//Setze alle Einträge in display auf c +void clear (char c) +{ + for (int i=0;i<WIDTH;i++) + { + for (int j=0;j<HEIGHT;j++) + { + screen[i][j]=c; + } + } +} + +//setze display [x][y] auf c +void putPoint (int x, int y, char c) +{ + screen[x][y]=c; +} + +//Gebe display[x][y] zurück +char getPoint (int x, int y) +{ + char c=screen[x][y]; + return c; +} + +//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus +void fill (int x, int y, char c, char o) +{ + if (getPoint(x,y)==o) + { + putPoint(x,y,c); + fill(x+1,y,c,o); + fill(x-1,y,c,o); + fill(x,y+1,c,o); + fill(x,y-1,c,o); + } +} + +//Gib display aus +void display (void) +{ + for (int i=0;i<HEIGHT;i++) + { + for (int j=0;j<WIDTH;j++) + { + printf("%c",screen[i][j]); + } + printf("\n"); + } +} + diff --git a/20151126/orzol/Text-Grafik-Bibliothek.h b/20151126/orzol/Text-Grafik-Bibliothek.h new file mode 100644 index 0000000..287e36b --- /dev/null +++ b/20151126/orzol/Text-Grafik-Bibliothek.h @@ -0,0 +1,8 @@ +#define HEIGHT 5 +#define WIDTH 10 + +extern void clear(char c); +extern void fill(int x, int y, char c, char o); +extern void putPoint(int x, int y, char c); +extern char getPoint(int x, int y); +extern void display(void); diff --git a/20151126/orzol/blink.sh b/20151126/orzol/blink.sh new file mode 100644 index 0000000..bd58446 --- /dev/null +++ b/20151126/orzol/blink.sh @@ -0,0 +1 @@ +while true; do clear; ./test; sleep 1; clear; ./test-pg; sleep 1; done diff --git a/20151126/orzol/stack.c b/20151126/orzol/stack.c new file mode 100644 index 0000000..db90ede --- /dev/null +++ b/20151126/orzol/stack.c @@ -0,0 +1,62 @@ +#include "stack.h" + +typedef struct +{ + int x, y; +} +coordinate; + +coordinate stack[STACK_SIZE]; +int stack_pointer = 0; + +int stack_empty (void) +{ + return !stack_pointer; +} + +void fatal_error (char *msg) +{ + fprintf (stderr, "%s\n", msg); + exit (1); +} + +void push (int x, int y) +{ + if (stack_pointer < 0 || stack_pointer >= STACK_SIZE) + fatal_error ("stack overflow"); + else + { + stack[stack_pointer].x = x; + stack[stack_pointer].y = y; + stack_pointer++; + } +} + +void pop (int *x, int *y) +{ + if (stack_pointer < 1 || stack_pointer > STACK_SIZE) + fatal_error ("stack underflow"); + else + { + --stack_pointer; + *x = stack[stack_pointer].x; + *y = stack[stack_pointer].y; + } +} + +void dump (void) +{ + if (stack_pointer < 0) + fatal_error ("stack underflow"); + else if (stack_pointer >= STACK_SIZE) + fatal_error ("stack overflow"); + else if (stack_pointer == 0) + printf ("stack is empty\n"); + else + { + printf ("stack:"); + for (int i = 0; i < stack_pointer; i++) + printf (" (%d,%d)", stack[i].x, stack[i].y); + printf ("\n"); + } +} diff --git a/20151126/orzol/stack.h b/20151126/orzol/stack.h new file mode 100644 index 0000000..b27f7ec --- /dev/null +++ b/20151126/orzol/stack.h @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <stdlib.h> + +#define STACK_SIZE (7 * 42) + +extern int stack_empty (void); +extern void push (int x, int y); +extern void pop (int *x, int *y); +extern void dump (void); diff --git a/20151126/orzol/test-1.c b/20151126/orzol/test-1.c new file mode 100644 index 0000000..3ea0c45 --- /dev/null +++ b/20151126/orzol/test-1.c @@ -0,0 +1,10 @@ +#include "Text-Grafik-Bibliothek.h" +#include <stdio.h> + +int main (void) +{ + clear ('.'); + putPoint (3, 1, '*'); + display (); + return 0; +} diff --git a/20151126/orzol/test-2.c b/20151126/orzol/test-2.c new file mode 100644 index 0000000..efb9c85 --- /dev/null +++ b/20151126/orzol/test-2.c @@ -0,0 +1,10 @@ +#include "Text-Grafik-Bibliothek.h" +#include <stdio.h> + +int main (void) +{ + clear ('.'); + putPoint (10, 1, '*'); + display (); + return 0; +} diff --git a/20151126/orzol/test-3.c b/20151126/orzol/test-3.c new file mode 100644 index 0000000..fc3262a --- /dev/null +++ b/20151126/orzol/test-3.c @@ -0,0 +1,10 @@ +#include "Text-Grafik-Bibliothek.h" +#include <stdio.h> + +int main (void) +{ + clear ('.'); + putPoint (3, 6, '*'); + display (); + return 0; +} diff --git a/20151126/orzol/test-4.c b/20151126/orzol/test-4.c new file mode 100644 index 0000000..c1fb84c --- /dev/null +++ b/20151126/orzol/test-4.c @@ -0,0 +1,23 @@ +#include "Text-Grafik-Bibliothek-20x15.h" +#include <stdio.h> + +int main (void) +{ + clear ('.'); + for (int i = 3; i < 13; i++) + putPoint (i, 3, '*'); + for (int j = 4; j < 11; j++) + putPoint (2, j, '*'); + putPoint (13, 4, '*'); + putPoint (12, 5, '*'); + putPoint (12, 6, '*'); + putPoint (13, 7, '*'); + putPoint (14, 8, '*'); + putPoint (14, 9, '*'); + putPoint (13, 10, '*'); + for (int i = 3; i < 13; i++) + putPoint (i, 11, '*'); + fill (5, 5, '%', '.'); + display (); + return 0; +} diff --git a/20151126/orzol/test-5.c b/20151126/orzol/test-5.c new file mode 100644 index 0000000..400e0ce --- /dev/null +++ b/20151126/orzol/test-5.c @@ -0,0 +1,23 @@ +#include "Text-Grafik-Bibliothek-20x15.h" +#include <stdio.h> + +int main (void) +{ + clear ('.'); + for (int i = 3; i < 13; i++) + putPoint (i, 3, '*'); + for (int j = 4; j < 11; j++) + putPoint (2, j, '*'); + putPoint (13, 4, '*'); + putPoint (12, 5, '*'); + putPoint (12, 6, '*'); + putPoint (13, 7, '*'); + putPoint (14, 8, '*'); + putPoint (14, 9, '*'); + putPoint (13, 10, '*'); + for (int i = 3; i < 13; i++) + putPoint (i, 11, 'A'); + fill (5, 5, '%', '.'); + display (); + return 0; +} diff --git a/20151126/orzol/test.c b/20151126/orzol/test.c new file mode 100644 index 0000000..36d29c9 --- /dev/null +++ b/20151126/orzol/test.c @@ -0,0 +1,22 @@ +#include "Text-Grafik-Bibliothek.h" +#include <stdio.h> + +int main(void) +{ +clear(' '); +display(); +printf("______________\n"); +putPoint(1,1,'A'); +display(); +printf("______________\n"); +fill(2,3,'*',' '); +display(); +printf("______________\n"); +putPoint(3,4,'B'); +display(); + + + + +return 0; +} diff --git a/20151126/stack-0.c b/20151126/stack-0.c new file mode 100644 index 0000000..08b4cbd --- /dev/null +++ b/20151126/stack-0.c @@ -0,0 +1,12 @@ +#include <stdio.h> + +int main (void) +{ + push (7); + push (13); + push (42); + printf ("%d\n", pop ()); /* 42 */ + printf ("%d\n", pop ()); /* 13 */ + printf ("%d\n", pop ()); /* 7 */ + return 0; +} diff --git a/20151126/stack-1.c b/20151126/stack-1.c new file mode 100644 index 0000000..a5d6278 --- /dev/null +++ b/20151126/stack-1.c @@ -0,0 +1,21 @@ +#include <stdio.h> + +void push (int x) +{ +} + +int pop (void) +{ + return 0; +} + +int main (void) +{ + push (7); + push (13); + push (42); + printf ("%d\n", pop ()); /* 42 */ + printf ("%d\n", pop ()); /* 13 */ + printf ("%d\n", pop ()); /* 7 */ + return 0; +} diff --git a/20151126/stack-2.c b/20151126/stack-2.c new file mode 100644 index 0000000..37eaac6 --- /dev/null +++ b/20151126/stack-2.c @@ -0,0 +1,27 @@ +#include <stdio.h> + +#define STACK_SIZE 42 + +int stack[STACK_SIZE]; +int stack_pointer = 0; + +void push (int x) +{ + stack[stack_pointer++] = x; +} + +int pop (void) +{ + return 0; +} + +int main (void) +{ + push (7); + push (13); + push (42); + printf ("%d\n", pop ()); /* 42 */ + printf ("%d\n", pop ()); /* 13 */ + printf ("%d\n", pop ()); /* 7 */ + return 0; +} diff --git a/20151126/stack-3.c b/20151126/stack-3.c new file mode 100644 index 0000000..ceacf17 --- /dev/null +++ b/20151126/stack-3.c @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <stdlib.h> + +#define STACK_SIZE 42 + +int stack[STACK_SIZE]; +int stack_pointer = 0; + +void fatal_error (char *msg) +{ + fprintf (stderr, "%s\n", msg); + exit (1); +} + +void push (int x) +{ + if (stack_pointer < 0 || stack_pointer >= STACK_SIZE) + fatal_error ("stack overflow"); + else + stack[stack_pointer++] = x; +} + +int pop (void) +{ + return 0; +} + +int main (void) +{ + push (7); + push (13); + push (42); + printf ("%d\n", pop ()); /* 42 */ + printf ("%d\n", pop ()); /* 13 */ + printf ("%d\n", pop ()); /* 7 */ + return 0; +} diff --git a/20151126/stack-4.c b/20151126/stack-4.c new file mode 100644 index 0000000..ceacf17 --- /dev/null +++ b/20151126/stack-4.c @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <stdlib.h> + +#define STACK_SIZE 42 + +int stack[STACK_SIZE]; +int stack_pointer = 0; + +void fatal_error (char *msg) +{ + fprintf (stderr, "%s\n", msg); + exit (1); +} + +void push (int x) +{ + if (stack_pointer < 0 || stack_pointer >= STACK_SIZE) + fatal_error ("stack overflow"); + else + stack[stack_pointer++] = x; +} + +int pop (void) +{ + return 0; +} + +int main (void) +{ + push (7); + push (13); + push (42); + printf ("%d\n", pop ()); /* 42 */ + printf ("%d\n", pop ()); /* 13 */ + printf ("%d\n", pop ()); /* 7 */ + return 0; +} diff --git a/20151126/stack-5.c b/20151126/stack-5.c new file mode 100644 index 0000000..d36031f --- /dev/null +++ b/20151126/stack-5.c @@ -0,0 +1,40 @@ +#include <stdio.h> +#include <stdlib.h> + +#define STACK_SIZE 42 + +int stack[STACK_SIZE]; +int stack_pointer = 0; + +void fatal_error (char *msg) +{ + fprintf (stderr, "%s\n", msg); + exit (1); +} + +void push (int x) +{ + if (stack_pointer < 0 || stack_pointer >= STACK_SIZE) + fatal_error ("stack overflow"); + else + stack[stack_pointer++] = x; +} + +int pop (void) +{ + if (stack_pointer < 1 || stack_pointer > STACK_SIZE) + fatal_error ("stack underflow"); + else + return stack[--stack_pointer]; +} + +int main (void) +{ + push (7); + push (13); + push (42); + printf ("%d\n", pop ()); /* 42 */ + printf ("%d\n", pop ()); /* 13 */ + printf ("%d\n", pop ()); /* 7 */ + return 0; +} diff --git a/20151126/stack-6.c b/20151126/stack-6.c new file mode 100644 index 0000000..5bed677 --- /dev/null +++ b/20151126/stack-6.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <stdlib.h> + +#define STACK_SIZE 42 + +int stack[STACK_SIZE]; +int stack_pointer = 0; + +void fatal_error (char *msg) +{ + fprintf (stderr, "%s\n", msg); + exit (1); +} + +void push (int x) +{ + if (stack_pointer < 0 || stack_pointer >= STACK_SIZE) + fatal_error ("stack overflow"); + else + stack[stack_pointer++] = x; +} + +int pop (void) +{ + if (stack_pointer < 1 || stack_pointer > STACK_SIZE) + { + fatal_error ("stack underflow"); + return 0; + } + else + return stack[--stack_pointer]; +} + +int main (void) +{ + push (7); + push (13); + push (42); + printf ("%d\n", pop ()); /* 42 */ + printf ("%d\n", pop ()); /* 13 */ + printf ("%d\n", pop ()); /* 7 */ + return 0; +} diff --git a/20151126/stack-7.c b/20151126/stack-7.c new file mode 100644 index 0000000..03e7ae5 --- /dev/null +++ b/20151126/stack-7.c @@ -0,0 +1,40 @@ +#include <stdio.h> +#include <stdlib.h> + +#define STACK_SIZE 42 + +int stack[STACK_SIZE]; +int stack_pointer = 0; + +__attribute__ ((noreturn)) void fatal_error (char *msg) +{ + fprintf (stderr, "%s\n", msg); + exit (1); +} + +void push (int x) +{ + if (stack_pointer < 0 || stack_pointer >= STACK_SIZE) + fatal_error ("stack overflow"); + else + stack[stack_pointer++] = x; +} + +int pop (void) +{ + if (stack_pointer < 1 || stack_pointer > STACK_SIZE) + fatal_error ("stack underflow"); + else + return stack[--stack_pointer]; +} + +int main (void) +{ + push (7); + push (13); + push (42); + printf ("%d\n", pop ()); /* 42 */ + printf ("%d\n", pop ()); /* 13 */ + printf ("%d\n", pop ()); /* 7 */ + return 0; +} diff --git a/20151126/stack-8.c b/20151126/stack-8.c new file mode 100644 index 0000000..1954814 --- /dev/null +++ b/20151126/stack-8.c @@ -0,0 +1,67 @@ +#include <stdio.h> +#include <stdlib.h> + +#define STACK_SIZE 42 + +int stack[STACK_SIZE]; +int stack_pointer = 0; + +void fatal_error (char *msg) +{ + fprintf (stderr, "%s\n", msg); + exit (1); +} + +void push (int x) +{ + if (stack_pointer < 0 || stack_pointer >= STACK_SIZE) + fatal_error ("stack overflow"); + else + stack[stack_pointer++] = x; +} + +int pop (void) +{ + if (stack_pointer < 1 || stack_pointer > STACK_SIZE) + { + fatal_error ("stack underflow"); + return 0; + } + else + return stack[--stack_pointer]; +} + +void dump (void) +{ + if (stack_pointer < 0) + fatal_error ("stack underflow"); + else if (stack_pointer >= STACK_SIZE) + fatal_error ("stack overflow"); + else if (stack_pointer == 0) + printf ("stack is empty\n"); + else + { + printf ("stack:"); + for (int i = 0; i < stack_pointer; i++) + printf (" %d", stack[i]); + printf ("\n"); + } +} + +int main (void) +{ + dump (); + push (7); + dump (); + push (13); + dump (); + push (42); + dump (); + printf ("%d\n", pop ()); /* 42 */ + dump (); + printf ("%d\n", pop ()); /* 13 */ + dump (); + printf ("%d\n", pop ()); /* 7 */ + dump (); + return 0; +} -- GitLab