Skip to content
Snippets Groups Projects
Commit e2e1ea66 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Beispielprogramme 16.1.2017

parent 85f30356
Branches
No related tags found
No related merge requests found
Showing with 820 additions and 0 deletions
#include <stdio.h>
#define FIFO_SIZE 10
int fifo[FIFO_SIZE];
int fifo_pointer = 0;
void push (int x)
{
fifo[fifo_pointer++] = x;
}
int pop (void)
{
return fifo[0];
for (int i = 1; i < fifo_pointer; i++)
fifo[i - 1] = fifo[i];
fifo_pointer--;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 10
int fifo[FIFO_SIZE];
int fifo_pointer = 0;
void push (int x)
{
fifo[fifo_pointer++] = x;
}
int pop (void)
{
int result = fifo[0];
for (int i = 1; i < fifo_pointer; i++)
fifo[i - 1] = fifo[i];
fifo_pointer--;
return result;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 10
int fifo[FIFO_SIZE];
int fifo_pointer = 0;
void push (int x)
{
fifo[fifo_pointer++] = x;
}
int pop (void)
{
int result = fifo[0];
for (int i = 1; i != fifo_pointer; i++)
fifo[i - 1] = fifo[i];
fifo_pointer--;
return result;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 10
int fifo[FIFO_SIZE];
int fifo_read = 0;
int fifo_write = 0;
void push (int x)
{
fifo[fifo_write++] = x;
}
int pop (void)
{
int result = fifo[fifo_read++];
return result;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 5
int fifo[FIFO_SIZE];
int fifo_read = 0;
int fifo_write = 0;
void push (int x)
{
fifo[fifo_write++] = x;
}
int pop (void)
{
int result = fifo[fifo_read++];
return result;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
push (256);
push (42);
push (1117);
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 5
int fifo[FIFO_SIZE];
int fifo_read = 0;
int fifo_write = 0;
void push (int x)
{
fifo[fifo_write++] = x;
}
int pop (void)
{
int result = fifo[fifo_read++];
return result;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
for (int i = 0; i < 1000; i++)
{
push (i);
printf ("%d\n", pop ());
}
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 10
int fifo[FIFO_SIZE];
int fifo_read = 0;
int fifo_write = 0;
void push (int x)
{
fifo[fifo_write++] = x;
if (fifo_write >= FIFO_SIZE)
fifo_write = 0;
}
int pop (void)
{
int result = fifo[fifo_read++];
if (fifo_read >= FIFO_SIZE)
fifo_read = 0;
return result;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
for (int i = 0; i < 1000; i++)
{
push (i);
printf ("%d\n", pop ());
}
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 10
int fifo[FIFO_SIZE];
int fifo_read = 0;
int fifo_write = 0;
void push (int x)
{
if ((fifo_write + 1) % FIFO_SIZE == fifo_read)
fprintf (stderr, "push(): FIFO is full\n");
else
{
fifo[fifo_write++] = x;
if (fifo_write >= FIFO_SIZE)
fifo_write = 0;
}
}
int pop (void)
{
if (fifo_read == fifo_write)
{
fprintf (stderr, "pop(): FIFO is empty\n");
return -1;
}
else
{
int result = fifo[fifo_read++];
if (fifo_read >= FIFO_SIZE)
fifo_read = 0;
return result;
}
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
for (int i = 0; i < 15; i++)
push (i);
return 0;
}
#include <stdio.h>
typedef struct
{
int content;
node *next;
} node;
int main (void)
{
node element3, element7, element137;
element3.content = 3;
element7.content = 7;
element137.content = 137;
node *first = &element3;
element3.next = &element7;
element7.next = &element137;
element137.next = NULL;
for (node *p = first; p; p = p->next)
printf ("%d\n", p->content);
return 0;
}
#include <stdio.h>
typedef struct node
{
int content;
struct node *next;
} node;
int main (void)
{
node element3, element7, element137;
element3.content = 3;
element7.content = 7;
element137.content = 137;
node *first = &element3;
element3.next = &element7;
element7.next = &element137;
element137.next = NULL;
for (node *p = first; p; p = p->next)
printf ("%d\n", p->content);
return 0;
}
#include <stdio.h>
typedef struct node
{
int content;
struct node *next;
} node;
int main (void)
{
node element3, element7, element137;
element3.content = 3;
element7.content = 7;
element137.content = 137;
node *first = &element3;
element3.next = &element7;
element7.next = &element137;
element137.next = NULL;
for (node *p = first; p; p = p->next)
printf ("%d\n", p->content);
node element5;
element5.content = 5;
element3.next = &element5;
element5.next = &element7;
for (node *p = first; p; p = p->next)
printf ("%d\n", p->content);
return 0;
}
#include <stdio.h>
typedef struct node
{
int content;
struct node *next;
} node;
void output_list (node *first)
{
for (node *p = first; p; p = p->next)
printf ("%d\n", p->content);
}
void insert_into_list (node *what, node *where)
{
where->next = what;
what->next = where->next;
}
int main (void)
{
node element3, element7, element137;
element3.content = 3;
element7.content = 7;
element137.content = 137;
node *first = &element3;
element3.next = &element7;
element7.next = &element137;
element137.next = NULL;
output_list (first);
node element5;
element5.content = 5;
insert_into_list (&element5, &element3);
output_list (first);
return 0;
}
#include <stdio.h>
typedef struct node
{
int content;
struct node *next;
} node;
void output_list (node *first)
{
for (node *p = first; p; p = p->next)
printf ("%d\n", p->content);
}
void insert_into_list (node *what, node *where)
{
what->next = where->next;
where->next = what;
}
int main (void)
{
node element3, element7, element137;
element3.content = 3;
element7.content = 7;
element137.content = 137;
node *first = &element3;
element3.next = &element7;
element7.next = &element137;
element137.next = NULL;
output_list (first);
node element5;
element5.content = 5;
insert_into_list (&element5, &element3);
output_list (first);
return 0;
}
#include <stdio.h>
#define STACK_SIZE 10
int stack[STACK_SIZE];
int stack_pointer = 0;
void push (int x)
{
stack[stack_pointer++] = x;
}
void push_at (int x, int pos)
{
for (int i = stack_pointer - 1; i >= pos; i--)
stack[i + 1] = stack[i];
stack[pos] = x;
stack_pointer++;
}
void push_sorted (int x)
{
int left = 0;
int right = stack_pointer;
while (left < right - 1)
{
printf ("%d %d\n", left, right);
int i = (left + right) / 2;
if (x < stack[i])
right = i;
else
left = i;
}
push_at (x, right);
}
int pop (void)
{
return stack[--stack_pointer];
}
void show (void)
{
printf ("stack:");
for (int i = 0; i < stack_pointer; i++)
printf (" %d", stack[i]);
printf ("\n");
}
int main (void)
{
push (3);
push (7);
push (137);
show ();
push_sorted (5);
show ();
push_sorted (256);
show ();
return 0;
}
#include <stdio.h>
#define STACK_SIZE 10
int stack[STACK_SIZE];
int stack_pointer = 0;
void push (int x)
{
stack[stack_pointer++] = x;
}
void push_at (int x, int pos)
{
for (int i = stack_pointer - 1; i >= pos; i--)
stack[i + 1] = stack[i];
stack[pos] = x;
stack_pointer++;
}
void push_sorted (int x)
{
int left = 0;
int right = stack_pointer;
while (left < right - 1)
{
int i = (left + right) / 2;
if (x < stack[i])
right = i;
else
left = i;
}
push_at (x, right);
}
int pop (void)
{
return stack[--stack_pointer];
}
void show (void)
{
printf ("stack:");
for (int i = 0; i < stack_pointer; i++)
printf (" %d", stack[i]);
printf ("\n");
}
int main (void)
{
push (3);
push (7);
push (137);
show ();
push_sorted (5);
show ();
push_sorted (256);
show ();
push_sorted (42);
push_sorted (13);
push_sorted (107);
show ();
return 0;
}
#include <stdio.h>
#define STACK_SIZE 10
int stack[STACK_SIZE];
int stack_pointer = 0;
void push (int x)
{
stack[stack_pointer++] = x;
}
void push_at (int x, int pos)
{
stack[pos] = x;
stack_pointer++;
}
int pop (void)
{
return stack[--stack_pointer];
}
void show (void)
{
printf ("stack:");
for (int i = 0; i < stack_pointer; i++)
printf (" %d", stack[i]);
printf ("\n");
}
int main (void)
{
push (3);
push (7);
push (137);
show ();
push_at (5, 1);
show ();
return 0;
}
#include <stdio.h>
#define STACK_SIZE 10
int stack[STACK_SIZE];
int stack_pointer = 0;
void push (int x)
{
stack[stack_pointer++] = x;
}
void push_at (int x, int pos)
{
for (int i = pos; i < stack_pointer; i++)
stack[i + 1] = stack[i];
stack[pos] = x;
stack_pointer++;
}
int pop (void)
{
return stack[--stack_pointer];
}
void show (void)
{
printf ("stack:");
for (int i = 0; i < stack_pointer; i++)
printf (" %d", stack[i]);
printf ("\n");
}
int main (void)
{
push (3);
push (7);
push (137);
show ();
push_at (5, 1);
show ();
return 0;
}
#include <stdio.h>
#define STACK_SIZE 10
int stack[STACK_SIZE];
int stack_pointer = 0;
void push (int x)
{
stack[stack_pointer++] = x;
}
void push_at (int x, int pos)
{
for (int i = stack_pointer - 1; i >= pos; i--)
stack[i + 1] = stack[i];
stack[pos] = x;
stack_pointer++;
}
int pop (void)
{
return stack[--stack_pointer];
}
void show (void)
{
printf ("stack:");
for (int i = 0; i < stack_pointer; i++)
printf (" %d", stack[i]);
printf ("\n");
}
int main (void)
{
push (3);
push (7);
push (137);
show ();
push_at (5, 1);
show ();
return 0;
}
#include <stdio.h>
#define STACK_SIZE 10
int stack[STACK_SIZE];
int stack_pointer = 0;
void push (int x)
{
stack[stack_pointer++] = x;
}
void push_at (int x, int pos)
{
for (int i = stack_pointer - 1; i >= pos; i--)
stack[i + 1] = stack[i];
stack[pos] = x;
stack_pointer++;
}
void push_sorted (int x)
{
int i = 0;
while (x >= stack[i])
i++;
push_at (x, i);
}
int pop (void)
{
return stack[--stack_pointer];
}
void show (void)
{
printf ("stack:");
for (int i = 0; i < stack_pointer; i++)
printf (" %d", stack[i]);
printf ("\n");
}
int main (void)
{
push (3);
push (7);
push (137);
show ();
push_sorted (5);
show ();
push_sorted (256);
show ();
return 0;
}
#include <stdio.h>
#define STACK_SIZE 10
int stack[STACK_SIZE];
int stack_pointer = 0;
void push (int x)
{
stack[stack_pointer++] = x;
}
void push_at (int x, int pos)
{
for (int i = stack_pointer - 1; i >= pos; i--)
stack[i + 1] = stack[i];
stack[pos] = x;
stack_pointer++;
}
void push_sorted (int x)
{
int left = 0;
int right = stack_pointer;
while (left < right)
{
int i = (left + right) / 2;
if (x < stack[i])
right = i;
else
left = i;
}
push_at (x, left);
}
int pop (void)
{
return stack[--stack_pointer];
}
void show (void)
{
printf ("stack:");
for (int i = 0; i < stack_pointer; i++)
printf (" %d", stack[i]);
printf ("\n");
}
int main (void)
{
push (3);
push (7);
push (137);
show ();
push_sorted (5);
show ();
push_sorted (256);
show ();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment