广告广告
  加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 2444 个阅读者
 
发表文章 发表投票 回覆文章
  可列印版   加为IE收藏   收藏主题   上一主题 | 下一主题   
小英 手机
数位造型
个人文章 个人相簿 个人日记 个人地图
路人甲
级别: 路人甲 该用户目前不上站
推文 x0 鲜花 x1
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片
推文 x0
[C/C++] 谁能帮帮~再做不出来就完ㄌ
这是我写ㄉ程式~要变成插入排序的地方有问题~刚开始先从0到50取10ㄍ乱数在从小排到大
Label1显示那时ㄍ乱数
Label2显示已用插入排列从小排到大的结果
ListBox1显示Label2计算的过程
下面是我做的程式但是在Label2的地方就有问题ㄌ
请帮我想想办法~因为刚学老师又没说ㄉ很清楚所以还不怎ㄇ懂


void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (flag == 0)
{
Label1->Caption="";
Label2->Caption=" ";
ListB ..

访客只能看到部份内容,免费 加入会员 或由脸书 Google 可以看到全部内容



我是电脑白痴~~希望加入这ㄍ论坛能吸收多一点电脑知识
献花 x0 回到顶端 [楼 主] From:台湾教育部 | Posted:2006-01-08 20:06 |
ziv999
数位造型
个人文章 个人相簿 个人日记 个人地图
路人甲
级别: 路人甲 该用户目前不上站
推文 x0 鲜花 x1
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

参考看看...


.h档
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:      // IDE-managed Components
  TButton *Button1;
  TLabel *Label1;
  TLabel *Label2;
  TListBox *ListBox1;
  void __fastcall Button1Click(TObject *Sender);
private:      // User declarations
  int a[10];
  int flag;
public:            // User declarations
  __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif



.cpp档
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  // 初始化
  Label1->Caption = "";
  Label2->Caption = "";
  ListBox1->Items->Clear();
  Button1->Caption = "产生列数";
  randomize();
  flag = 0;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if (flag == 0) {
    // 随机产生值
    Label1->Caption = "";
    Label2->Caption = "";
    ListBox1->Items->Clear();
    for (int i = 0; i < 10; i++) {
        a = random(50);
        Label1->Caption = Label1->Caption + a + ",";
    }
    Button1->Caption = "插入排列";
  }
  else {
    Label2->Caption = "";
    // insertion_sort
    for (int i = 0; i < 10 ; i++) {
        int next = a ;
        int j;
        for (j = i - 1 ; j >= 0 && next < a[j] ; j--) {
          a[j+1] = a[j];
        }
        a[j + 1] = next ;

        Label2->Caption = "";
        for (int m = 0; m < 10 ; m++) {
          Label2->Caption = Label2->Caption + a[m] + ",";
        }
        ListBox1->Items->Add(Label2->Caption);
    }
    Button1->Caption = "产生列数";
  }
  flag = 1 - flag;
}


献花 x0 回到顶端 [1 楼] From:台湾中华电信 | Posted:2006-02-01 16:35 |

首页  发表文章 发表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.011342 second(s),query:16 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言