/**
|
|
* Datei: pointStack.c
|
|
* Funktionen vom Stack Programm
|
|
*
|
|
* Rainer Hihn
|
|
*/
|
|
#include "pointStack.h"
|
|
|
|
/**
|
|
* globale Variable, die auf das
|
|
* oberste Element des Stacks zeigt
|
|
*/
|
|
STACK_POINT_PTR stackTop = NULL;
|
|
|
|
void push(POINT pushPoint)
|
|
{
|
|
/**
|
|
* temporaere Variable
|
|
*/
|
|
STACK_POINT_PTR stackPoint = (STACK_POINT_PTR) malloc(sizeof(STACK_POINT));
|
|
|
|
/**
|
|
* debugging
|
|
* printf("%d \n", stackPoint);
|
|
*/
|
|
|
|
/**
|
|
* Abbruchbedingung, falls zu wenig Speicher zur Verfuegung steht
|
|
*/
|
|
if(stackPoint == NULL)
|
|
{
|
|
printf("nicht genug Speicher zur Verfuegung ... Ende \n");
|
|
exit(1);
|
|
}
|
|
|
|
/*
|
|
* Punnkt speichern und
|
|
* stackTop auf den aktuellen Wert setzen
|
|
*/
|
|
stackPoint->p = pushPoint;
|
|
stackPoint->next = stackTop;
|
|
stackTop = stackPoint;
|
|
|
|
return;
|
|
}
|
|
|
|
POINT pop()
|
|
{
|
|
/**
|
|
* stackTop und nextStackTop
|
|
* zwischenspeichern
|
|
*/
|
|
STACK_POINT firstStackPoint = *stackTop;
|
|
|
|
/**
|
|
* Speicher vom obersten
|
|
* Stack-Element freigeben
|
|
*/
|
|
|
|
/**
|
|
* debugging
|
|
* printf("%d \n", stackTop);
|
|
*/
|
|
free(stackTop);
|
|
|
|
/**
|
|
* stackTop auf das ehemals
|
|
* zweite Element des Stacks setzen
|
|
*/
|
|
stackTop = firstStackPoint.next;
|
|
|
|
/**
|
|
* Punkte vom ehemals ersten Element
|
|
* zurueckgeben
|
|
*/
|
|
return firstStackPoint.p;
|
|
}
|
|
|
|
int isEmpty()
|
|
{
|
|
/**
|
|
* wenn next auf NULL zeigt
|
|
* dann ist dies das letzte Element
|
|
* des Stacks
|
|
* und es wird '1' zurueckgegeben
|
|
*/
|
|
if(stackTop == NULL)
|
|
{
|
|
return 1;
|
|
}
|
|
else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
void printStackElement(POINT aPoint)
|
|
{
|
|
printf("Punkt x: %f, Punkt y: %f, Punkt z: %f \n", aPoint.rX, aPoint.rY, aPoint.rZ);
|
|
return;
|
|
}
|
|
|