-
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
作业2-12-Cloud #30
Merged
Merged
作业2-12-Cloud #30
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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,109 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
#include<time.h> | ||
#define STACK_INIT_SIZE 100 | ||
#define STACKINCREMENT 10 | ||
#define SElemType int | ||
|
||
typedef struct _Sqstack | ||
{ | ||
SElemType *base; | ||
SElemType *top; | ||
int Stacksize; | ||
}Sqstack; | ||
|
||
typedef enum | ||
{ | ||
OK, | ||
ERROR, | ||
OVERFLOW | ||
}Status; | ||
|
||
typedef enum{ | ||
true, | ||
false | ||
}bool; | ||
|
||
Status InitStack(Sqstack *s); | ||
void Push(Sqstack* ,SElemType ); | ||
Status Pop(Sqstack* , SElemType* ); | ||
void conversion (Sqstack , int ); | ||
bool StackEmpty(Sqstack* ); | ||
|
||
|
||
Status InitStack(Sqstack *s) | ||
{ | ||
s->base = (SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType)); | ||
/*if(StackEmpty)*/ | ||
if(!s->base){ | ||
return OVERFLOW; | ||
} | ||
s->top = s->base; | ||
s->Stacksize = STACK_INIT_SIZE; | ||
return OK; | ||
} | ||
|
||
void Push(Sqstack *s, SElemType e) | ||
{ | ||
//e�²����ջ��Ԫ�� | ||
if(s->top - s->base >= s->Stacksize){ | ||
s->base = (SElemType *)realloc(s->base ,(STACK_INIT_SIZE + STACKINCREMENT)*sizeof(SElemType)); | ||
while(!s->base) | ||
{ | ||
s->base = (SElemType *)realloc(s->base ,(STACK_INIT_SIZE + STACKINCREMENT)*sizeof(SElemType)); | ||
}//�洢����ʧ�ܣ��������·��� | ||
s->top = s->base + s->Stacksize; | ||
s->Stacksize += STACKINCREMENT; | ||
} | ||
*(s->top )= e; | ||
s->top ++; | ||
} | ||
|
||
bool StackEmpty(Sqstack *s) | ||
{//���ջΪ�գ�����true ���շ���false | ||
/*if(s->top == s->base) | ||
return true; | ||
else | ||
return false;*///WWW1 | ||
if(s){ | ||
return s->base == s->top; | ||
} | ||
return true;//HDD | ||
} | ||
|
||
Status Pop(Sqstack *s, SElemType* e) | ||
{ | ||
if(StackEmpty(s)) | ||
return OVERFLOW; | ||
*e = *(--s->top); | ||
//s->top--;//WWW2--�˴���Ҫfree��? | ||
return OK; | ||
} | ||
|
||
void conversion (Sqstack _s, int _d) | ||
{ | ||
int e; | ||
int number = rand()%1024; | ||
//int number = 1348; | ||
printf("���ɵ��������%d (10) = ",number); | ||
while (number) { | ||
Push(&_s, number % _d); | ||
number = number/_d; | ||
} | ||
while (!StackEmpty(&_s)) { | ||
Pop(&_s, &e); | ||
printf ( "%d",e); | ||
} | ||
printf("(8)\n"); | ||
} | ||
int main() | ||
{ | ||
Sqstack S; | ||
int d = 8; //������ | ||
int input = rand()%1024; | ||
srand(time(NULL)); | ||
InitStack(&S); | ||
conversion (S,d) ; | ||
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,87 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
#define length 10 | ||
|
||
typedef struct LNode{ | ||
int data; | ||
struct LNode *next ; | ||
}LNode; | ||
typedef struct LNode *LinkList; | ||
|
||
typedef enum { | ||
true, | ||
false | ||
}bool; | ||
|
||
void travle(LinkList p); | ||
void CreatList(LinkList L,int n); | ||
void MergeList(LinkList La,LinkList Lb,LinkList Lc); | ||
|
||
void travle(LinkList p){ | ||
|
||
int i; | ||
printf("��������:"); | ||
//p = L_->next | ||
for( i = 0 ;i <length;i++){ | ||
//printf("%d ",(L_+i)->data); | ||
printf("%d ",p->data ); | ||
p = p->next ; | ||
} | ||
printf("\n"); | ||
} | ||
|
||
void CreatList(LinkList L,int n){ | ||
LNode *p; | ||
int i; | ||
L = (LinkList)malloc( sizeof(LNode) ); | ||
L->next = NULL;//������������ͷ��� | ||
if(L) | ||
printf("ͷ�ڵ㴴���ɹ���\n"); | ||
for(i = n; i > 0;--i){ | ||
p = (LinkList)malloc(sizeof(LNode)); | ||
if(p) | ||
printf("�ɹ�����һ���ڵ�ռ䣬������һ��������"); | ||
scanf("%d",& p->data ); | ||
p->next = L->next ;//��һ������ʱL->next����һ�β���Ľڵ���������������� | ||
L->next = p;//������һ�������ɵĽ������ȥ�� | ||
} | ||
travle(L); | ||
//printf("����һ����������"); | ||
//for(int i ;i <length;i++){ | ||
// printf("%d",L+i); | ||
//} | ||
|
||
} | ||
|
||
void MergeList(LinkList La,LinkList Lb,LinkList Lc){ | ||
LinkList pa,pb,pc; | ||
pa = La->next ; | ||
pb = Lb->next ; | ||
Lc = pc = La; | ||
while(pa && pb){ | ||
if( pa->data <= pb->data ){ | ||
pc->next = pa; | ||
pc = pa; | ||
pa = pa->next ; | ||
} | ||
else{ | ||
pc->next = pb; | ||
pc = pb; | ||
pb = pc->next; | ||
} | ||
} | ||
pc->next = pa ? pa : pb; | ||
free(Lb); | ||
} | ||
|
||
int main(){ | ||
LNode list_a,list_b,list_c; | ||
|
||
CreatList(&list_a,length); | ||
CreatList(&list_b,length); | ||
MergeList(&list_a,&list_b,&list_c); | ||
travle(&list_c); | ||
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,143 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
#include<time.h> | ||
#define STACK_INIT_SIZE 100 | ||
#define STACKINCREMENT 10 | ||
#define SElemType char | ||
typedef struct _Sqstack | ||
{ | ||
SElemType *base; | ||
SElemType *top; | ||
int Stacksize; | ||
}Sqstack; | ||
|
||
typedef enum | ||
{ | ||
OK, | ||
ERROR, | ||
OVERFLOW | ||
}Status; | ||
|
||
typedef enum{ | ||
true, | ||
false | ||
}bool; | ||
|
||
Status InitStack(Sqstack *s); | ||
void Push(Sqstack* ,SElemType* ); | ||
Status Pop(Sqstack* , SElemType* ); | ||
bool StackEmpty(Sqstack* ); | ||
|
||
|
||
Status InitStack(Sqstack *s) | ||
{ | ||
s->base = (SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType)); | ||
/*if(StackEmpty)*/ | ||
if(!s->base){ | ||
return OVERFLOW; | ||
} | ||
s->top = s->base; | ||
s->Stacksize = STACK_INIT_SIZE; | ||
return OK; | ||
} | ||
|
||
void Push(Sqstack *s, SElemType *e) | ||
{ | ||
//e�²����ջ��Ԫ�� | ||
if(s->top - s->base >= s->Stacksize){ | ||
s->base = (SElemType *)realloc(s->base ,(STACK_INIT_SIZE + STACKINCREMENT)*sizeof(SElemType)); | ||
while(!s->base) | ||
{ | ||
s->base = (SElemType *)realloc(s->base ,(STACK_INIT_SIZE + STACKINCREMENT)*sizeof(SElemType)); | ||
}//�洢����ʧ�ܣ��������·��� | ||
s->top = s->base + s->Stacksize; | ||
s->Stacksize += STACKINCREMENT; | ||
} | ||
*(s->top )= *e; | ||
s->top ++; | ||
} | ||
|
||
bool StackEmpty(Sqstack *s) | ||
{//���ջΪ�գ�����true ���շ���false | ||
/*if(s->top == s->base) | ||
return true; | ||
else | ||
return false;*///WWW1 | ||
if(s){ | ||
return s->base == s->top; | ||
} | ||
return true;//HDD | ||
} | ||
|
||
Status Pop(Sqstack *s, SElemType* e) | ||
{ | ||
if(StackEmpty(s)) | ||
return OVERFLOW; | ||
*e = *(s->top - 1); | ||
s->top--;//WWW2--�˴���Ҫfree��? | ||
return OK; | ||
} | ||
|
||
|
||
Status ParenthesisJudge(char f, char l){ | ||
switch(f){ | ||
case '(' :if(l == ')'){ | ||
return OK; | ||
} | ||
else { | ||
return ERROR; | ||
} | ||
break; | ||
case '[' :if(l == ']'){ | ||
return OK; | ||
} | ||
else { | ||
return ERROR; | ||
} | ||
break; | ||
case '{' :if(l == '}'){ | ||
return OK; | ||
} | ||
else { | ||
return ERROR; | ||
} | ||
break; | ||
} | ||
|
||
|
||
} | ||
|
||
Status ParenthesisTest(Sqstack *_s){ | ||
char now,_t; | ||
char * t = &_t;//������Ϊ��ӭ������Pop�ĵ��� | ||
printf("����������(���롮�����Խ�������)....\n"); | ||
scanf("%c",&now); | ||
if(now != '!'){ | ||
Push(_s,&now); | ||
}//ջ��Ԫ�� | ||
scanf("%c",&now); | ||
while(now != '!'){ | ||
if( ParenthesisJudge( *(_s->top - 1),now) == OK ){ | ||
Pop(_s,t); | ||
} | ||
else{ | ||
Push(_s, &now); | ||
} | ||
scanf("%c",&now); | ||
} | ||
if(StackEmpty(_s)){ | ||
return OK; | ||
}else{ | ||
return ERROR; | ||
} | ||
} | ||
int main(){ | ||
Sqstack S; | ||
InitStack(&S); | ||
if (!ParenthesisTest(&S)){ | ||
printf("������������"); | ||
}else{ | ||
printf("�������벻ƥ�䡣"); | ||
} | ||
return 0; | ||
} |
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.
应该加入default语句