
Untitled
By: a guest on
Apr 25th, 2012 | syntax:
C | size: 1.60 KB | hits: 12 | expires: Never
#include <stdio.h>
#include <stdlib.h>
typedef struct graphElement{
int label;
struct graphElement *node;
} graphElement;
typedef struct graphLine{
struct graphElement *nodes[2];
struct line *nextElement;
} graphLine;
//
typedef struct stack{
graphLine *stackElement;
struct stack *nextItem;
} stack;
stack *stackTop;
int elementsOfStack = 0;
void createStack(){
stack *newStack;
newStack = (stack*)malloc(sizeof(stack));
newStack -> stackElement = NULL;
newStack -> nextItem = NULL;
stackTop = newStack;
}
graphLine *popStack(stack *stackItem){
graphLine *tempLine;
tempLine = stackItem -> stackElement;
stackTop = stackTop -> nextItem;
free(stackItem);
return tempLine;
}
void pushStack(stack *stackItem, graphLine *newLine){
if(stackTop->stackElement == NULL){
stackItem -> stackElement = newLine;
stackTop = stackItem;
} else{
stack *stackNewItem = (stack*)malloc(sizeof(stack));
stackNewItem -> stackElement = newLine;
stackNewItem -> nextItem = stackItem;
stackTop = stackNewItem;
}
}
//
void createGraph(int *newLabels){
int index = 0;
if(!elementsOfStack){
createStack();
}
graphLine *newLine = (graphLine*)malloc(sizeof(graphLine));
while(index < 2){
graphElement *newElement = (graphElement*)malloc(sizeof(graphElement));
newElement -> label = newLabels[index];
newLine -> nodes[index] = newElement;
pushStack(stackTop, newLine);
index++;
elementsOfStack++;
}
}
int main(){
return 0;
}