Skip to content
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 5 commits into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
109 changes: 109 additions & 0 deletions 2017-1/Cloud/tesr3-1.c
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;

}
87 changes: 87 additions & 0 deletions 2017-1/Cloud/test2-12.c
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;
}


143 changes: 143 additions & 0 deletions 2017-1/Cloud/test3-2.c
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;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

应该加入default语句



}

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;
}
Loading