Upload New File
This commit is contained in:
parent
00d25de4d9
commit
c9f744a2d5
108
chained_functions.c
Normal file
108
chained_functions.c
Normal file
@ -0,0 +1,108 @@
|
||||
#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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user