主题:我这个程序怎么不能运行运行啊,麻烦各位高手看看
#include<stdio.h>
#define MAXSIZE 100
typedef struct{
int key;
}record;
typedef struct{
record r[MAXSIZE+1];
int length;
}tab;
void binary(tab *tb){
int i,j,left,right,mid;
for(i=2;i<=tb->length;i++)
{
tb->r[0].key=tb->r[i].key;
left=1;
right=i-1;
while(left<=right)
{
mid=(left+right)/2;
if(tb->r[i].key<tb->r[mid].key)
right=mid-1;
else
left=mid+1;
}
for(j=i-1;j>=left;j--)
tb->r[j+1].key=tb->r[j].key;
tb->r[left].key=tb->r[0].key;
}
}
void init_sequence(tab *p)
{
p->length=0;
}
void inser_sequence(tab *p,int x)
{
if(p->length==MAXSIZE)
{printf("不能插入!");exit(1);}
p->r[p->length].key=x;
p->length=p->length+1;
}
void printsequence(tab p)
{
int i;
if(!p.length) printf("顺序表是空的");
else
for(i=0;i<=p.length;i++)
printf("%d",p.r[p.length].key);
}
main()
{
tab *p;
inser_sequence(p,10);
inser_sequence(p,5);
inser_sequence(p,4);
inser_sequence(p,2);
inser_sequence(p,15);
inser_sequence(p,20);
inser_sequence(p,30);
inser_sequence(p,36);
binary(p);
printsequence(*p);
}
[color=FF0000][/color]
#define MAXSIZE 100
typedef struct{
int key;
}record;
typedef struct{
record r[MAXSIZE+1];
int length;
}tab;
void binary(tab *tb){
int i,j,left,right,mid;
for(i=2;i<=tb->length;i++)
{
tb->r[0].key=tb->r[i].key;
left=1;
right=i-1;
while(left<=right)
{
mid=(left+right)/2;
if(tb->r[i].key<tb->r[mid].key)
right=mid-1;
else
left=mid+1;
}
for(j=i-1;j>=left;j--)
tb->r[j+1].key=tb->r[j].key;
tb->r[left].key=tb->r[0].key;
}
}
void init_sequence(tab *p)
{
p->length=0;
}
void inser_sequence(tab *p,int x)
{
if(p->length==MAXSIZE)
{printf("不能插入!");exit(1);}
p->r[p->length].key=x;
p->length=p->length+1;
}
void printsequence(tab p)
{
int i;
if(!p.length) printf("顺序表是空的");
else
for(i=0;i<=p.length;i++)
printf("%d",p.r[p.length].key);
}
main()
{
tab *p;
inser_sequence(p,10);
inser_sequence(p,5);
inser_sequence(p,4);
inser_sequence(p,2);
inser_sequence(p,15);
inser_sequence(p,20);
inser_sequence(p,30);
inser_sequence(p,36);
binary(p);
printsequence(*p);
}
[color=FF0000][/color]