-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
一次性提交之前尚未提交的五次作业QAQ #189
Open
byswez
wants to merge
1
commit into
CUCCS:master
Choose a base branch
from
byswez:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
一次性提交之前尚未提交的五次作业QAQ #189
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
|
||
|
||
|
||
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
运行没有显示正确结果