| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 494 人关注过本帖
标题:内部排序直接插入排序问题解决不了,那里错了啊
只看楼主 加入收藏
cwl168
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2012-12-14
结帖率:8.33%
收藏
已结贴  问题点数:15 回复次数:3 
内部排序直接插入排序问题解决不了,那里错了啊
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define MASIZE 7
#define lENGTH 7
typedef int KeyType;
typedef struct
{
       KeyType key;
      // InfoType otherinfo;
}RedType;
typedef struct
{
      RedType r[MASIZE+1];
      int length;
}SqList;
void IntiList(SqList *L)
{   
    L->length=lENGTH;
    printf("please input numbers:\n");
    for(int i=1;i<=L->length;i++)
    {
         scanf("%d",&L->r[i]);
    }
     
}

void ListTravese(SqList *L)
{
      printf("the result is :\n");
      for( int i=1;i<=L->length;i++)
          printf("%d ",L->r[i]);
}
// 对顺序表L做直接插入排序
void InsertSort(SqList *L)
{
    int i,j;
    for(i=2;i<=L->length;++i)
    {
        if(L->r[i]->key<L->r[i-1]->key) //"<",需将L.r[i]插入有序子表
            L->r[0]=L->r[i];//复制为哨兵
            for(j=i-1;(L->r[0].key<L->r[j]->key);--j)
                L->r[j+1]=L->r[j];//记录后移
            L->r[j+1]=L->r[0];//插入到正确位置
    }

}
int main()
{
    SqList L;
    IntiList(&L);
    ListTravese(&L);
    InsertSort(&L);//直接插入排序
    //printf("the length:%d")
    return 0;
}
搜索更多相关主题的帖子: void numbers include please result 
2013-01-01 21:18
不玩虚的
Rank: 9Rank: 9Rank: 9
来 自:四川
等 级:贵宾
威 望:10
帖 子:331
专家分:1301
注 册:2012-12-9
收藏
得分:15 
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define MASIZE 7
#define lENGTH 7
typedef int KeyType;
typedef struct
{
       KeyType key;
      // InfoType otherinfo;
}RedType;
typedef struct
{
      RedType r[MASIZE+1];
      int length;
}SqList;
void IntiList(SqList *L)
{   
    L->length=lENGTH;
    printf("please input numbers:\n");
    for(int i=1;i<=L->length;i++)
    {
         scanf("%d",&L->r[i]);
    }//楼主输出格式不好看自己弄下 ,表示c语言不太会。插入排序我给你改成while()循环,要是还是想要for()循环的说下,我写下学习下。
     
}

void ListTravese(SqList *L)
{
      //printf("the result is :\n");
      for( int i=1;i<=L->length;i++)
          printf("%d ",L->r[i]);
}
// 对顺序表L做直接插入排序
void InsertSort(SqList *L)
{
    int i,j;
    for(i=2;i<=L->length;++i)
    {        L->r[0]=L->r[i];
        j=i-1;
        while(L->r[0].key<L->r[j].key) //"<",需将L.r[i]插入有序子表
        {    L->r[j+1]=L->r[j];
            j--;
        }
            L->r[j+1]=L->r[0];//插入到正确位置
    }

}
int main()
{
    SqList L;
    IntiList(&L);
    printf("未排序的数列 :\n");
    ListTravese(&L);
    InsertSort(&L);//直接插入排序
    printf("排序后的数列 :\n");
     ListTravese(&L);
    //printf("the length:%d")
    return 0;
}

同学习......同进步....你帮我......我帮你.....上善若水.....
2013-01-02 15:43
不玩虚的
Rank: 9Rank: 9Rank: 9
来 自:四川
等 级:贵宾
威 望:10
帖 子:331
专家分:1301
注 册:2012-12-9
收藏
得分:0 
不好意思注释写错位置了。提醒楼主的结构体不太熟,应该多看下。顺便问下楼主现在是学数据结构?是的话一定要东教教我。我数据结构没学好。遗憾啊。。。。。

同学习......同进步....你帮我......我帮你.....上善若水.....
2013-01-02 15:48
cwl168
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2012-12-14
收藏
得分:0 
是的,我在学数据结构,互相学习啊
2013-01-02 19:18
快速回复:内部排序直接插入排序问题解决不了,那里错了啊
数据加载中...
 
   



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

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