Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions 2017-1/byswsz/建立二叉树/建立二叉树.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include<stdio.h>
#include<stdlib.h>
typedef char TElemType;
typedef int Status;

int count = 0;


//�������Ķ��������Ĵ洢��ʾ��
typedef struct BiTnode {
TElemType data;
struct BiTNode *lchild, *rchild;//���Һ���ָ�룻

}BiTnode, *BiTree;
//



Status CreateBiTree(BiTree *T, char *c)
{
TElemType ch;
ch = c[count];
count++;
if (ch == '*')
{
*T = NULL;
}
else
{
if (!(*T = (BiTree)malloc(sizeof(BiTnode))))
{
exit(-1);
}
(*T)->data = ch;//���ɸ����
CreateBiTree(&(*T)->lchild, c);//����������
CreateBiTree(&(*T)->rchild, c);//����������
}
return 1;
}
void postorderTraversal(BiTree T)
{
if (T == NULL)
{
printf("*");
return;
}
postorderTraversal(T->lchild);
postorderTraversal(T->rchild);
printf("%c ", T->data);
}



int main()
{
BiTree t;
TElemType c[20];
scanf("%s", c);
CreateBiTree(&t, c);
printf("����������˳��Ϊ\n");
postorderTraversal(t);
return 0;
}
195 changes: 195 additions & 0 deletions 2017-1/byswsz/行编辑程序/3.2.3-行编辑程序.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define SIZE 100 //�洢�ռ��ʼ������

#define STACKINCREMENT 10 //�洢�ռ��������
typedef int Status;
typedef char SElemType;
//��˳��ջ���ж���
typedef struct Sq_Stack {

SElemType *base;

SElemType *top;

int stacksize;
} SqStack;
//����
typedef enum {

OK,
ERROR,
OVERFLOW,
TRUE,
FALSE ,
} Status;




/*#define OVERFLOW
#define OK
#define
#define
#define ERROR*/
Status InitStack(SqStack *pS);//�����ջ
SElemType Pop(SqStack *pS, SElemType *pe);//����ջ��Ԫ�أ�
Status Push(SqStack *pS, SElemType e);//������Ԫ�أ�
Status StackEmpty(SqStack *pS);//����@֮�����ջ֮���ж��Ƿ������
Status DestroyStack(SqStack *pS);//����#������ջ��

Status InitStack(SqStack *pS) {

(*pS).base = (SElemType *)malloc(SIZE * sizeof(SElemType));

if (!(*pS).base)
exit (OVERFLOW); //�洢����ʧ��

(*pS).top = (*pS).base;

(*pS).stacksize = SIZE;

return OK;

}



SElemType Pop(SqStack *pS, SElemType *pe) {

if ((*pS).top == (*pS).base) return ERROR;

pe = --(*pS).top;

return *pe;
}



Status Push(SqStack *pS, SElemType e) {

if ((*pS).top - (*pS).base >= (*pS).stacksize) {

(*pS).base = (SElemType *)realloc((*pS).base, ((*pS).stacksize + STACKINCREMENT) * sizeof(SElemType));

if (!(*pS).base) exit (OVERFLOW);

(*pS).top = (*pS).base + (*pS).stacksize;

(*pS).stacksize += STACKINCREMENT;

}

*(*pS).top++ = e;

return OK;

}



Status DestroyStack(SqStack *pS) {

(*pS).top = NULL;

(*pS).stacksize = 0;

free((*pS).base);

return OK;

}



Status StackEmpty(SqStack *pS) {

if ((*pS).base == (*pS).top) return TRUE;

else return FALSE;

}
//
void Lineedit() {

int i = 0;

char ch[200] = "whli##ilr#e(s#*s)\noutchar@\nputchar(*s=#++)\0";
//������
SqStack S;

SElemType e = ch[i];

InitStack(&S); //�����ջ

while (ch[i] != '\0') {

e = ch[i];

switch (ch[i]) {

case '#':

Pop(&S, &e); break;

case '@': {

if (StackEmpty(&S)) break;

while (e != '\n') { Pop(&S, &e); };

if (StackEmpty(&S) || e == '\n') { Push(&S, e); break; } break;

}//����Ϊ��ջ

default:

Push(&S, ch[i]); break;//��Ч�ַ���ջ

};

i++;

//����ջ�׵�ջ����ջ���ַ����������ù��̵�������



};

char pa[100];

int j = 0;

while (!StackEmpty(&S)) {

pa[j] = Pop(&S, &e);

j++;

};//�ų�#��@���֮�����������뵽������

do {

j--;

printf("%c", pa[j]);

} while (j >= 0);

DestroyStack(&S);

}//���ϸ���ַ��������

int main() {

Lineedit();

return OK;

}




Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

运行没有显示正确结果

Loading