| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 456 人关注过本帖
标题:求问大神 用折返查找 加冒泡法 找元素 这边哪边错了
只看楼主 加入收藏
在QQ
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-6-2
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
求问大神 用折返查找 加冒泡法 找元素 这边哪边错了
#define M 50
#include<stdio.h>
#include<conio.h>
int search(int *st,int key ,int length)
{
    int low =1 , high=length,mid,s;
    while (low <= high)
    {
        mid=(high +low)/2;
        if (key == st[mid])
            return(mid);
        else if (key < st[mid])
            high = mid-1;
        else low =mid +1;
    }
    return s;
}
void BubbleSort(int  *st[],int length)
{
    int n,i,j,x;
    char change;
    n = length;   change=1;
    for (i =1;i <=n-1&&change; i++)
    {
        change = 0;
        for (j=1; j<=n-i;j++)
            if (st[j]>st[j+1])
            {
                x=*st[j];
                st[j]=st[j+1];
                *st[j+1]=x;
                change =1;
            }
    }
}

main()
{
    int i,length;
    int low,high,mid;
    int key,s;
    int st[M];
    printf("Please input SSTable length:\n");
    scanf("%d",&length);
    printf("Please input SSTable data:\n");
    for(i=1;i <= length; i++)
    {
        printf("%d:\t",i);
        scanf("%d",&st[i]);
        key=st[i];
    }
    printf("according to the order from small to large:\n");
     void  BubbleSort(int  *st[],int length);
    for(i=1;i <= length; i++)
    {
        ptintf("%d:\t",i);
        ptintf("%d",st[i]);
        printf("\n");
        
    }
   
    printf("Please input Search Key:\n");
    scanf("%d",&key);
    printf("\n");
    s=search(*st,key,length);
    if(s==0)
        printf("%d is not here\n",key);
    if(s!=0)
    {
        printf("%d is st[%d]\n",key,s);
    }
    getch();
}

下面是错误提示:
-------------------Configuration: 8 - Win32 Debug--------------------
Compiling...
8.c
D:\c语言\Debug\Debug\8.c(53) : error C2143: syntax error : missing ';' before 'type'
D:\c语言\Debug\Debug\8.c(56) : warning C4013: 'ptintf' undefined; assuming extern returning int
D:\c语言\Debug\Debug\8.c(65) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
D:\c语言\Debug\Debug\8.c(65) : warning C4024: 'search' : different types for formal and actual parameter 1
执行 cl.exe 时出错.

8.obj - 1 error(s), 0 warning(s)
搜索更多相关主题的帖子: include search change return 元素 
2014-06-02 16:17
韶志
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:斗气大陆
等 级:贵宾
威 望:44
帖 子:2223
专家分:13592
注 册:2013-3-22
收藏
得分:20 
ptintf("%d:\t",i);
 ptintf("%d",st[i]);

 错误提示不会看?  其它可能还有错误

三十年河东,三十年河西,莫欺少年穷!
2014-06-02 16:32
在QQ
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-6-2
收藏
得分:0 
回复 2 楼 韶志
没有看见  谢谢啦
2014-06-02 16:34
在QQ
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-6-2
收藏
得分:0 
#define M 50
#include<stdio.h>
#include<conio.h>
int search(int *st,int key ,int length)
{
    int low =1 , high=length,mid,s;
    while (low <= high)
    {
        mid=(high +low)/2;
        if (key == st[mid])
            return(mid);
        else if (key < st[mid])
            high = mid-1;
        else low =mid +1;
    }
    return s;
}
void BubbleSort(int  *st[],int length)
{
    int n,i,j,x;
    char change;
    n = length;   change=1;
    for (i =1;i <=n-1&&change; i++)
    {
        change = 0;
        for (j=1; j<=n-i;j++)
            if (st[j]>st[j+1])
            {
                x=*st[j];
                st[j]=st[j+1];
                *st[j+1]=x;
                change =1;
            }
    }
}

main()
{
    int i,length;
    int low,high,mid;
    int key,s;
    int st[M];
    printf("Please input SSTable length:\n");
    scanf("%d",&length);
    printf("Please input SSTable data:\n");
    for(i=1;i <= length; i++)
    {
        printf("%d:\t",i);
        scanf("%d",&st[i]);
        key=st[i];
    }
    printf("according to the order from small to large:\n");
    for(i=1;i <= length; i++)
    {
        printf("%d:\n",i);
        printf("%d",st[i]);
        printf("\n");
       BubbleSort(int  *st[],int length)
        
    }
    printf("Please input Search Key:\n");
    scanf("%d",&key);
    printf("\n");
    s=search(*st,key,length);
    if(s==0)
        printf("%d is not here\n",key);
    if(s!=0)
    {
        printf("%d is st[%d]\n",key,s);
    }
    getch();
}

--------------------Configuration: 8 - Win32 Debug--------------------
Compiling...
8.c
D:\c语言\Debug\Debug\8.c(58) : error C2143: syntax error : missing ')' before 'type'
D:\c语言\Debug\Debug\8.c(58) : error C2198: 'BubbleSort' : too few actual parameters
D:\c语言\Debug\Debug\8.c(58) : error C2059: syntax error : ')'
D:\c语言\Debug\Debug\8.c(64) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
D:\c语言\Debug\Debug\8.c(64) : warning C4024: 'search' : different types for formal and actual parameter 1
D:\c语言\Debug\Debug\8.c(74) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

8.obj - 1 error(s), 0 warning(s)
加了一行调用的 就不行了 而且刚刚运行的时候冒泡法没起作用
求解
2014-06-02 16:40
快速回复:求问大神 用折返查找 加冒泡法 找元素 这边哪边错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012669 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved