printf("2.括号匹配。\n");
printf("0.操作结束。\n");
printf("请输入选择:");
scanf("%d",&select);
while(select!=0)
{
switch(select)
{
case 1:
conversion();
break;
case 2:
printf("\n输入括号,以#结束:");
if(Compare()==TURE)
printf("匹配\n");
else
printf("不匹配\n");
break;
case 0:
printf("操作结束,退出程序。");
break;
}
printf("\n1.进制转换。\n");
printf("2.括号匹配。\n");
printf("0.操作结束。\n");
printf("请输入选择:");
scanf("%d",&select);
}
}
*************************************************************************************************
矩阵
**************************************************************************************************
#include "stdio.h"
#define OK 1
#define ERROR 0
#define MAXSIZE 120
typedef int ElemType;
typedef int Status;
typedef struct {
int i,j;
ElemType e;
}Triple;
typedef struct{
Triple data[MAXSIZE + 1];
int mu,nu,tu;
}TSMatrix;
#include "1.h"
void InitMatrix(int A[P+1][N+1])
{ int i,j;
printf("请输入一个4行5列的矩阵\n");
for(i=1;i<=P;i++)
for(j=1;j<=N;j++)
scanf("%d",&A[i][j]);
}
TSMatrix MatrixToTriple(int A[P+1][N+1],TSMatrix M)
{ int row,col,k=0;
for(row=1;row<=P;row++)
for(col=1;col<=N;col++)
if(A[row][col]!=0)
{ k++;
M.data[k].i=row;
M.data[k].j=col;
M.data[k].e=A[row][col];
}
M.mu=P; M.nu=N; M.tu=k;
return M;
}
TSMatrix FastTransposeSMatrix(TSMatrix M,TSMatrix T)
{ int col,t,p,q;
int num[N+1],cpot[N+1];
T.mu=M.nu; T.nu=M.mu; T.tu=M.tu;
if(T.tu)
{ for(col=1;col<=M.nu;++col) num[col]=0;
for(t=1;t<=M.tu;++t) ++num[M.data[t].j];
cpot[1]=1;
for(col=2;col<=M.nu;++col)
cpot[col]=cpot[col-1]+num[col-1];
for(p=1;p<=M.tu;++p)
{ col=M.data[p].j;
q=cpot[col];
T.data[q].i=M.data[p].j;
T.data[q].j=M.data[p].i;
T.data[q].e=M.data[p].e;
++cpot[col];
}
}
return T;
}
void PrintMatrix(TSMatrix T)
{ int B[N+1][P+1]={0};
int i,j,k=1;
for(i=1;i
{ B[i][j]=T.data[k].e;++k;}
printf("output TransposeMatrix\n");
for(i=1;i<=N;i++)
{for(j=1;j<=P;j++)
printf("%4d",B[i][j]);
printf("\n");
}
}
int main()
{ int A[P+1][N+1]={0};
TSMatrix M={{0},0,0,0},T={{0},0,0,0};
InitMatrix(A);
M=MatrixToTriple(A,M);
T=FastTransposeSMatrix(M,T);
PrintMatrix(T);
return OK;
}
***********************************************************************************************
二叉树
***********************************************************************************************
#include "stdio.h"
#include "malloc.h"
#include "iostream.h"
typedef int Status;
typedef int TElemType;
#define OK 1
#define ERROR 0
#define OVERFLOW -1
//二叉树的二叉链表储存
typedef struct BiTNode
{
TElemType data;
struct BiTNode *lchild,*rchild;
}BiTNode, *BiTree;
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
//#define NULL 0;
typedef int Status;
typedef int SElemType;
typed