109 lines
1.8 KiB
C
109 lines
1.8 KiB
C
|
#include "chained_functions.h"
|
||
|
#include <stdio.h>
|
||
|
|
||
|
//for information purposes: mom== momentan ((;
|
||
|
|
||
|
messdaten*
|
||
|
insertFirst (messdaten* firstelem, messdaten* newelement)
|
||
|
{
|
||
|
newelement->next = firstelem;
|
||
|
return newelement;
|
||
|
}
|
||
|
|
||
|
messdaten*
|
||
|
insertLast (messdaten* firstelem, messdaten* newelement)
|
||
|
{
|
||
|
messdaten * mom = firstelem;
|
||
|
while (mom->next != NULL)
|
||
|
{
|
||
|
mom = mom->next;
|
||
|
}
|
||
|
mom->next = newelement;
|
||
|
newelement->next = NULL;
|
||
|
return firstelem;
|
||
|
}
|
||
|
|
||
|
messdaten*
|
||
|
insertPos (messdaten* firstelem, messdaten* newelement, int pos)
|
||
|
{
|
||
|
pos--;
|
||
|
messdaten * mom = firstelem;
|
||
|
int n = 0;
|
||
|
while (mom->next != NULL)
|
||
|
{
|
||
|
if (n == pos)
|
||
|
{
|
||
|
newelement->next = mom->next;
|
||
|
mom->next = newelement;
|
||
|
return firstelem;
|
||
|
}
|
||
|
n++;
|
||
|
mom = mom->next;
|
||
|
|
||
|
}
|
||
|
fprintf (stderr, "failed to allocate list element!!");
|
||
|
return firstelem;
|
||
|
}
|
||
|
|
||
|
messdaten*
|
||
|
deleteFirst (messdaten* firstelem)
|
||
|
{
|
||
|
messdaten * temp = firstelem;
|
||
|
|
||
|
temp = firstelem->next;
|
||
|
free (firstelem);
|
||
|
return temp;
|
||
|
}
|
||
|
|
||
|
messdaten*
|
||
|
deleteLast (messdaten* firstelem)
|
||
|
{
|
||
|
messdaten * mom = firstelem;
|
||
|
messdaten * temp = NULL;
|
||
|
while (mom->next != NULL)
|
||
|
{
|
||
|
temp = mom;
|
||
|
mom = mom->next;
|
||
|
}
|
||
|
free (temp->next);
|
||
|
temp->next = NULL;
|
||
|
return firstelem;
|
||
|
}
|
||
|
|
||
|
messdaten*
|
||
|
deletePos (messdaten* firstelem, int pos)
|
||
|
{
|
||
|
pos--;
|
||
|
messdaten * mom = firstelem;
|
||
|
messdaten * temp = NULL;
|
||
|
int n = 0;
|
||
|
while (mom->next != NULL)
|
||
|
{
|
||
|
if (n == pos)
|
||
|
{
|
||
|
temp = mom->next;
|
||
|
mom->next = mom->next->next;
|
||
|
free (temp);
|
||
|
return firstelem;
|
||
|
}
|
||
|
n++;
|
||
|
mom = mom->next;
|
||
|
|
||
|
}
|
||
|
printf ("failed to allocate list element!!");
|
||
|
return firstelem;
|
||
|
}
|
||
|
|
||
|
messdaten*
|
||
|
deleteAll (messdaten* firstelem)
|
||
|
{
|
||
|
messdaten * temp;
|
||
|
while (firstelem != NULL)
|
||
|
{
|
||
|
temp = firstelem;
|
||
|
firstelem = firstelem->next;
|
||
|
free (temp);
|
||
|
}
|
||
|
return firstelem;
|
||
|
}
|