标题:求解,感激。迷茫中。
只看楼主
wjjjsy
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-4-21
 问题点数:0 回复次数:0 
求解,感激。迷茫中。
数据结构。。。
有能搞明白的吗?
有没有人可以帮助我一下。
感谢感谢。

#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
}


感谢帮助者。感谢爱莫能助者。
搜索更多相关主题的帖子: STACK stack struct bool 求解 
2008-04-21 15:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-210233-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.348481 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved