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

Beispielprogramme 22.1.2018

parent 1a09281b
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -732,6 +732,7 @@
\color{red}
\item[7.1] Stack und FIFO
\item[7.2] Verkettete Listen
\color{black}
\item[7.3] Bäume
\end{itemize}
\end{itemize}
......@@ -962,8 +963,6 @@
\end{frame}
\iffalse
\subsection{Verkettete Listen}
\begin{frame}
......@@ -1010,7 +1009,9 @@
In Array (Stack, FIFO) \dots
\begin{itemize}
\item
einfügen: $\mathcal{O}(n)$
in der Mitte einfügen: $\mathcal{O}(n)$
\item
wahlfreier Zugriff: $\mathcal{O}(1)$
\item
suchen: $\mathcal{O}(n)$
\item
......@@ -1025,7 +1026,9 @@
In (einfach) verkettete/r Liste \dots
\begin{itemize}
\item
einfügen: $\mathcal{O}(1)$
in der Mitte einfügen: $\mathcal{O}(1)$
\item
wahlfreier Zugriff: $\mathcal{O}(n)$
\item
suchen: $\mathcal{O}(n)$
\item
......@@ -1044,7 +1047,9 @@
In (ausbalancierten) Bäumen \dots
\begin{itemize}
\item
einfügen: $\mathcal{O}(\log n)$
in der Mitte einfügen: $\mathcal{O}(\log n)$
\item
wahlfreier Zugriff: $\mathcal{O}(\log n)$
\item
suchen: $\mathcal{O}(\log n)$
\item
......@@ -1056,6 +1061,8 @@
\end{frame}
\iffalse
\subsection{Bäume}
\begin{frame}[fragile]
......@@ -1162,8 +1169,8 @@
\begin{itemize}
\color{medgreen}
\item[7.1] Stack und FIFO
\color{red}
\item[7.2] Verkettete Listen
\color{red}
\item[7.3] Bäume
\end{itemize}
\end{itemize}
......
#include <stdio.h>
typedef struct node
{
int content;
struct node *next;
} node;
int main (void)
{
node *first = NULL;
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *next;
} node;
node *first = NULL;
void push (int x)
{
node *n = malloc (sizeof (node));
n->content = x;
n->next = NULL;
if (first)
{
node *p = first;
while (p->next)
p = p->next;
p->next = n;
}
else
first = n;
}
int main (void)
{
push (3);
push (7);
push (137);
push (1117);
for (node *p = first; p; p = p->next)
printf ("%d\n", p->content);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *next;
} node;
node *first = NULL;
node *last = NULL;
void push (int x)
{
node *n = malloc (sizeof (node));
n->content = x;
n->next = NULL;
if (first)
last->next = n;
else
first = n;
last = n;
}
int main (void)
{
push (3);
push (7);
push (137);
push (1117);
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 A = { 65, NULL };
node *first = &A;
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 C = { 67, NULL };
node B = { 66, &C };
node A = { 65, &B };
node *first = &A;
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;
node *first = NULL;
void push (int x)
{
node n;
n.content = x;
n.next = NULL;
first = &n;
}
int main (void)
{
push (3);
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;
node *first = NULL;
node n;
void push (int x)
{
n.content = x;
n.next = NULL;
first = &n;
}
int main (void)
{
push (3);
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;
node *first = NULL;
node n;
void push (int x)
{
n.content = x;
n.next = NULL;
first = &n;
}
int main (void)
{
push (3);
push (7);
for (node *p = first; p; p = p->next)
printf ("%d\n", p->content);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *next;
} node;
node *first = NULL;
void push (int x)
{
node *n = malloc (sizeof (node));
n->content = x;
n->next = NULL;
first = n;
}
int main (void)
{
push (3);
push (7);
for (node *p = first; p; p = p->next)
printf ("%d\n", p->content);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *next;
} node;
node *first = NULL;
void push (int x)
{
node *n = malloc (sizeof (node));
n->content = x;
n->next = NULL;
if (first)
first->next = n;
else
first = n;
}
int main (void)
{
push (3);
push (7);
for (node *p = first; p; p = p->next)
printf ("%d\n", p->content);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *next;
} node;
node *first = NULL;
void push (int x)
{
node *n = malloc (sizeof (node));
n->content = x;
n->next = NULL;
if (first)
{
if (first->next)
{
if (first->next->next)
first->next->next->next = n;
else
first->next->next = n;
}
else
first->next = n;
}
else
first = n;
}
int main (void)
{
push (3);
push (7);
push (137);
push (1117);
for (node *p = first; p; p = p->next)
printf ("%d\n", p->content);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment