Stack

add

/* add an element to the top of the stack */
void add(stack_pointer *top, element item) {
	stack_pointer temp = (stack_pointer)malloc(sizeof(struct stack));
	if(IS_FULL(temp)) {
		fprintf(stderr, "the memory is full\\n");
		exit(1);
	}
	temp->item = item;
	temp->link = *top;
	*top = temp;
}

delete

/* delete an element from the stack */
element delete(stack_pointer *top) {
	stack_pointer temp = *top;
	element item;
	if(IS_EMPTY(temp)) {
		fprintf(stderr, "the stack is empty\\n");
		exit(1);
	}
	item = temp->item;
	*top = temp->link;
	free(temp);
	return item;
}

queue

add

/* add an element to the rear of the queue */
void addq(queue_pointer *front, queue_pointer *rear, element item) {
	queue_pointer temp = (queue_pointer)malloc(sizeof(struct queue));
	if(IS_FULL(temp)) {
		fprintf(stderr, "the memory is full\\n");
		exit(1);
	}
	temp->item = item;
	temp->link = NULL;
	if(*front)
		(*rear)->link = temp;
	else *front = temp;
		*rear = temp;
}

delete

/* delete an element from the queue */
element deleteq(queue_pointer *front) {
queue_pointer temp = *front;
element item;
if(IS_EMPTY(*front)) {
	fprintf(stderr, "the queue is empty\\n");
	exit(1);
}
item = temp->item;
*front = temp->link;
free(temp);
return item;
}

sparse matrix

하..기싫다