题目内容

填空实现向队列中插入元素的功能Status EnQueue(struct SqQueue *Q,QElemType e){//向队列中插入元素e的函数if((Q->rear+1)1==Q->front)//判断队列是否为满return OVERFLOW;Q->base[2 ]=e;//向队尾插入元素,队尾指针后移一位Q->rear=3;return OK;}

查看答案
更多问题

填空实现将元素插入栈顶的操作Status Push(struct SqStack *S, SElemType e )//入栈函数:将元素e插入栈中{if(1 ==2 ) {//判断栈是否已满S->base=(SElemType*)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(SElemType));if(!S->base) exit(OVERFLOW);S->top=S->base+S->stacksize;S->stacksize+=STACKINCREMENT;}//栈满的处理3 ;//栈顶指针上移,将元素e插入栈顶return OK;}

请完成下列二叉树的递归遍历算法#include #include #define OK 1#define ERROR 0#define TRUE 1#define FALSE 0#define OVERFLOW -2typedef int status;/*二叉树的二叉链表存储表示*/typedef struct BiNode{char Data;struct BiNode* lChild;struct BiNode* rChild; //左右孩子指针}BiNode,*pBiNode;BiNode *pRoot=NULL;status Visit(char Data){printf("%c",Data);return OK;}/*建立二叉链表*/status CreateTree(BiNode** pTree){//按先序次序输入二叉树中结点值,空格表示空树//构造二叉链表表示的二叉树char ch;scanf("%c",&ch);if(ch==' '){(*pTree)=NULL;}else{(*pTree)=(BiNode*)malloc(sizeof(BiNode));(*pTree)->Data=ch;CreateTree(&((*pTree)->lChild));CreateTree(&((*pTree)->rChild));}return OK;}/*先序遍历二叉树,递归算法*/status PreOrderTraval(BiNode* pTree){if(pTree){if(Visit(pTree->Data)){if(PreOrderTraval(pTree->lChild)){if(PreOrderTraval(pTree->rChild)){return OK;}}}return ERROR;}else{return OK;}}/*中序遍历二叉树,递归算法*/status InOrderTraval(BiNode* pTree){if(pTree){if(InOrderTraval(1)){if(Visit(2)){if(InOrderTraval(3)){return OK;}}}return ERROR;}else{return OK;}}/*后序遍历二叉树,递归算法*/status PostOrderTraval(BiNode* pTree){if(pTree){if(4){if(PostOrderTraval(pTree->rChild)){if(Visit(pTree->Data)){return OK;}}}return ERROR;}else{return OK;}}main(){system("cls");CreateTree(&pRoot);printf("\nPreOrder:");PreOrderTraval(pRoot);printf("\n");printf("\nInOrder:");InOrderTraval(pRoot);printf("\n");printf("\nPostOrder:");PostOrderTraval(pRoot);printf("\n");getch();}

链表插入操作:在线性表的第i-1个数据元素与第i个数据元素之间插入一个由符号e表示的数据元素。int ListInsert_L(LinkList L, int i, ElemType e) {//向链表中第i位插入数据estruct LNode *s,*p;int j;p = 1 ; j = 1;//p指针指向线性链表的头结点while (p && j <2) //循环查找第i-1位作为数据e的插入位置{ p =3 ; ++j; } //p指针向前移动if (!p || j > i-1)return ERROR;s =(LNode*)malloc(sizeof(LNode)); //见下图1)if ( s == NULL) return ERROR;s->4= e; //将插入数据e的值赋值给s结点的数据域1)5 =p->next ; 6=s; //旧链断开,新链产生2)3)return OK;}

删除链表中第i个结点:ElemType ListDelete_L(LinkList L, int i) {LinkList p,q;int j;ElemType e;p = L; j = 0;while (p->next && j < i-1) { p = p->next; ++j; }if (!(p->next) || j > i-1)return ERROR;q =1; 2=q->next;e = q->data; free(3);return e;}

答案查题题库