博文

利用链表对多项式运算(2005-05-07 22:48:00)

摘要:#include<stdio.h> #include<stdlib.h> typedef struct node { float coef; int expn; struct node *next; }node,*linklist; linklist L1,L2,head; int num; void create_linklist(linklist *S) { int i=0; linklist p; float data; head=NULL; printf("\nplease input nodes' coef (group by expn(from 0 ~%d)):\n",num-1); while(i<num) { p=(node *)malloc(num*sizeof(node)); if(!p) { printf("overflow!"); exit(0); } p->next=head; head=p; scanf("%f",&data); head->coef=data; head->expn=i; i++; } *S=head; printf("\nhaving created a linklist:\n"); i=0; p=*S; printf("%d",num); while(p!=NULL) { printf(" %f",p->coef); p=p->next; } } void computer_linklist() { linklist p1,p2; float data; printf("\nhow many expns of the expression do you want to set up?:"); scanf("%d",&num); printf("\nstart to create linklist L1:"); create_linklist(&L1); printf("\nstart to create linklise L2:"); ......

阅读全文(4347) | 评论:0

括号匹配问题(2005-05-07 11:34:00)

摘要:#include<stdio.h> #include<stdlib.h> #define N 20 typedef struct { char data[N]; int top; }stack; stack *L; void initstack(stack *S) { S->top=-1; } int  Isemptystack(stack *S) { return S->top==-1; } int Isfullstack(stack *S) { return S->top==N-1; } void pushstack(stack *S,char ch) { if(Isfullstack(S)) { printf("overflow!!!"); exit(0); } S->data[++S->top]=ch; } void popstack(stack *S) { if(Isemptystack(S)) { printf("the stack is empty!!"); exit(0); } S->top--; } void ismatch(char a[N],stack *S) { int i; for(i=0;i<N;i++) { if(a[i]=='(') { if(S->data[S->top]==')') {printf("the wrong input format!\n"); exit(0); } pushstack(S,a[i]); } else if(a[i]==')') { if(Isemptystack(S)) { printf("the wrong input format!\n"); exit(0); } popstack(S); } } if(Isemptystack(S)) printf("success for match!\n"); else printf("cannot match\n"); } main() { char array[N]; initstack(L); printf("please in......

阅读全文(3951) | 评论:0

球钟问题(栈和队列的应用)(2005-05-04 13:01:00)

摘要:问题的描述: http://www.programfan.com/club/showbbs.asp?id=73789 #include<stdio.h> #include<conio.h> #include<malloc.h> #define N 30                                                            /*27<=N<=127*/ #define NULL 0 typedef struct Qnode                                              /*定义队列的接点类型*/ { int data; struct Qnode *next; }Qnode,*Queueptr; Queueptr p,q; typedef struct { Queueptr front; Queueptr rear; }linkQueue; linkQueue *Q;  &......

阅读全文(3435) | 评论:0

24点扑克牌的游戏编程(2005-05-03 13:06:00)

摘要:经过调试以后,正常通过: 注意你的tc路径和输入的格式: #include<stdio.h> #include<graphics.h> #include<ctype.h> #include<time.h> #include<stdlib.h> #include<string.h> #define COL 100 #define COM 40 #define N 20 char after[N]; char  p[4][13]={ {'A','2','3','4','5','6','7','8','9','0','J','Q','K'}, {'A','2','3','4','5','6','7','8','9','0','J','Q','K'}, {'A','2','3','4','5','6','7','8','9','0','J','Q','K'}, {'A','2','3','4','5','6','7','8','9','0','J','Q','K'} }; typedef struct stack                                                                           /*定义栈1存放运算符*/ { char stack[N]; int top; }stac......

阅读全文(4558) | 评论:0

简单的四则运算(栈的应用)(2005-05-01 13:01:00)

摘要:这个程序自己写的有些局限,可惜只能对0~9的四则运算起作用,我正在对它进行改进,希望各位能提出好的意见,谢谢!! #include<stdio.h> #include<math.h> #include<stdlib.h> #include<ctype.h> #define maxism 15 typedef struct stack { char stack[maxism]; int top; }stack; stack *L; char after[maxism]; void initialstack(stack *T) { T->top=0; } void push(stack *T,int x) { T->top++; T->stack[L->top]=x; } void change() { int i=0,j,m=0; char str[maxism],ch; printf("please enter the compute expression(only contained +,-,*,/,(,),begin and end with '#'):\n"); gets(str); i++; ch=str[i]; initialstack(L); while(ch!='#') {                       switch(ch)                             {               &nbs......

阅读全文(4945) | 评论:0

简易的学生管理系统(2005-04-29 22:54:00)

摘要:没有来的及调试,请多多包涵: 这个程序的源代码有不少漏洞,正在修改之中,请提出批评指正,谢谢!!! #include"stdio.h" #include"string.h" #include"stdlib.h" #define N 3 #define increase 4 #define NULL 0 typedef struct stud { char name[15]; int age; float score; struct stud *next; }L;/*定义表的类型*/ L*p,*that,*othernew,*x,*you,*head; L * enter_record ()/*加入记录*/ { int n,i=0; float m; L *new; head=new=(L*)malloc(N*sizeof(L)); if(!new) { printf("failure for applying room!\n"); exit(0); } else { p=new; while(i<N) { i++; printf("please enter name:"); fflush(stdin); gets(p->name); printf("\n"); printf("enter age:"); fflush(stdin); scanf("%d",&n); printf("\n"); p->age=n; printf("enter the score:"); fflush(stdin); scanf("%f",&m); p->score=m; p=p->next; } } return head; } L *show_record()/*显示记录*/ { int c=1; L *this; printf("the records are:\n"); this=head; while(this->next!=NULL) { printf("the %d th is......

阅读全文(4048) | 评论:0

报数问题(循环链表的应用)(2005-04-28 12:11:00)

摘要:问题; 一个经常出现的问题: n个人围成一圈,从第一个人开始1,2,3报数,当一个人报到数3时,退出.接下的从一在开始往下抱,遇3退出,依次循环下去,直到只剩一个人,输出这个人的原始数,如:输入7 结果输出;4 #include<stdio.h> #include<alloc.h> #include<conio.h> typedef struct node { int data; struct node *next; }node,*cllist; cllist head; void createlist(void) { cllist p,new,new1; int i; printf("please input the number of people:"); scanf("%d",&i); printf("\n"); while(i<=1) { printf("error due to the wrong input ! please input it again!\n"); scanf("%d",&i); } head=NULL; p=new=(node *)malloc(sizeof(node)); if(!new) {   printf("overflow!"); exit(0); } new->next=head; head=new; head->data=i; while(i>1) {   new1=(node *)malloc(sizeof(node)); if(!new1)    {     printf("overflow.\n"); exit(0); } i--; new1->next=head; head=new1; head->data=i; } p->next=head; p=p->next; while(head->next!=head)    { &nb......

阅读全文(5126) | 评论:0

sinx求值(2005-04-13 22:18:00)

摘要:#include<stdio.h> #include<math.h> #define PI 3.14159 #define EPS 1e-7 main() { double x,sum=0,an; int n; clrscr(); printf("please input the number:\n"); scanf("%lf",&x); an=x; n=1; do {   sum+=an;   ++n;   an*=-x*x/((2*n-2)*(2*n-1)); }while(fabs(an)<EPS); printf("the sin(%.4f) is:%.4f",x,sum); } ......

阅读全文(3289) | 评论:0

魔方距阵(2005-04-12 16:14:00)

摘要:#include<stdio.h> #define N 15 main() { int i,j,row,cloum,size,square[N][N],count; clrscr(); printf("please enter the square size(odd && <=15):\n"); scanf("%d",&size); while(size%2==0||size>15||size<3) { printf("error due to the wrng input!please input it again!\n"); scanf("%d",&size); } for(i=0;i<size;i++)   for(j=0;j<size;j++)   square[i][j]=0; i=0;j=(size-1)/2; square[i][j]=1; for(count=2;count<=size*size;count++) { row=i-1<0?(size-1):(i-1); cloum=j-1<0?(size-1):(j-1); if(square[row][cloum]) i=(++i)%size; else {i=row; j=j-1<0?(size-1):(j-1); } square[i][j]=count; } printf("the %d square is:\n",size); for(i=0;i<size;i++)   { for(j=0;j<size;j++) printf("%d",square[i][j]); printf("\n"); } } ......

阅读全文(3695) | 评论:0

选择排序法(2005-04-12 11:37:00)

摘要:#include<stdio.h> #include<math.h> #define wap(x,y,t) ((t)=(x),(x)=(y),(y)=(t)) #define max 12 void sort(int a[],int x); main() { int a[max],i,j; clrscr(); printf("how many elems do you want to compare?number(<=12):\n"); scanf("%d",&i); while(i>12||i<=0) { printf("error due to the wrong input,please input it again!\n"); scanf("%d",&i); } printf("\nplease enter the numbers:\n"); for(j=0;j<i;j++) { fflush(stdin);   scanf("%d",&a[j]);   } printf("\nthe original numbers is:\n"); for(j=0;j<i;j++) { printf("%d",a[j]); printf("/t/t"); } printf("/n"); sort(a,i); } void sort(int a[],int x) { int i,j,maxsu,k,m,temp; for(i=0;i<(x-1);i++) {   maxsu=a[i];   for(j=i;j<x;j++)   {     if(a[j]<maxsu)      {      maxsu=a[j];   &n......

阅读全文(4358) | 评论:0