very new to C. creating a stack and implementing the create(), push(), pop(), empty() routines into another class. my stack class looks like:
Code:
struct list_item {
char data;
struct list_item *next;
}
typedef struct list_item stackItem;
extern stackItem *header;
void create();
void push();
void pop();
int empty ();
not sure if this is all ok. but then my operator class follows:
#include <stdio.h>
#include <alloc.h>
#include "stackhead.h"
stackItem *header;
void create() {
stackItem *newStack;
newStack = (stackItem *) malloc( sizeof(stackItem) );
newStack->data=NULL;
newStack->next=NULL;
};
void push(stackItem **head, char newData) {
stackItem *tempItem;
tempItem = (stackItem *) malloc( sizeof(stackItem) );
tempItem->data = newData;
tempItem->next = *head;
*head = tempItem;
};
void pop(stackItem head) {
*head->next = header;
};
int empty(stackItem **head) {
if (*head == NULL) {
return 1; } else {
return 0;
}
};
Not sure how correct any of these routines are. I am having the most trouble with pop, will not even compile. The dereference operators are still new to me so I am still struggling with those too. Would just like some feedback on what I have so far.