求解,感激。迷茫中。
数据结构。。。有能搞明白的吗?
有没有人可以帮助我一下。
感谢感谢。
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define MAX 10
struct StackNode {
char *title;
char *singer;
struct StackNode *next;
};
typedef struct StackNode STACKNODE;
struct Stack {
int stackSize;
STACKNODE *top;
STACKNODE *bottom;
};
typedef struct Stack STACK;
void initStack(STACK *stack);
void printStack(STACK *stack);
bool isEmpty(STACK *stack);
bool isFull(STACK *stack);
void insertCD(STACK *stack);
void push(STACK *Sstack, STACKNODE *node);
void removeCD(STACK *stack);
void pop(STACK *stack, STACKNODE *removedNode);
void main()
{
STACK *stack
char cmd;
printf("******************* Choose Command!! *******************\n");
printf("+: push, -: pop, F: full check, E: empty check \n");
printf("Q: Quit\n");
printf("*********************************************************\n");
stack = (STACK *)malloc(sizeof(STACK));
initStack(stack);
do {
printf("Command:");
cmd - getch();
putch(cmd);
cmd = toupper(cmd);
switch (cmd)
{
case '+':
insertCD(stack);
break;
case '-':
removeCD(stack)
break;
case 'E':
if (isEmpty(stack)) printf ("Stack is empty!\n");
else printf ("Stack isn't full!\n");
break;
case 'F':
if (isFull(stack)) printf ("Stack is full!\n");
else printf ("Stack isn't full!\n");
break;
case 'Q':
break;
default :
printf ("\nWrong command! Retry!\n");
}
printStack(stack);
} while (cmd !='Q' );
}
void printStack(STACK *stack)
{
int nSerial=1;
STACKNODE *tempCursor, *cursor;
tempCursor = stack->bottom;
cursor = stack->top;
if (isEmpty(stack))
{
printf("Stack is empty!\n");
}
else
{
printf("CD list\n");
printf ("=============================================\n");
while(tempCursor != NULL)
{
printf("%d : %s (%s)\n",nSerial, tempCursor->title,tempCursor->singer);
tempCursor = tempCursor->next;
nSerial++;
}
printf("n");
}
}
void initStack(STACK *stack)
{
//要写的地方1
}
bool isEmpty(STACK *stack)
{
//要写的地方2
}
bool isFull(STACK *stack)
{
//要写的地方3
}
void inserCD(STACK *stack)
{
STACKNODE *tempNode;
tempNode = (STACKNODE *)malloc(sizeof(STACKNODE));
tempNode->next = NULL;
tempNode->title = (char *)malloc(sizeof(CHAR)*20);
tempNode->singer = (char *)malloc(sizeof(char)*20);
printf ("=========================================================\n");
printf ("CD Title : ");
gets(tempNode->title);
printf ("Singer : ");
gets(tempNode->singer);
printf ("\n");
printf ("=========================================================\n");
push(stack,tempNode);
}
void push(STACK *stack, STACKNODE *node)
{
//要写的地方4
}
void removeCD(STACK *stack)
{
STACKNODE *deletedNode;
deletedNode = (STACKNODE *)malloc(sizeof(STACKNODE));
deletedNode->next = NULL;
deletedNode->title = NULL;
deletedNode->singer = NULL;
pop(stack, deletedNode);
printf("\nRempved CD : %s (%s)\n",deletedNode->title,deletedNode->singer);
}
void pop(STACK *stack, STACKNODE *removedNode)
{
//要写的地方5
}
感谢帮助者。感谢爱莫能助者。