c++中cout<

hj1028545502 2010-12-14 02:11:05
#include <iostream.h>
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#define LS(a,b) ((a)<(b))
#define LL(a,b) ((a)>(b))
#define MAXSIZE 30000
typedef int KeyType;
typedef struct
{
int key;
}RedType;
typedef struct
{
RedType r[MAXSIZE+1];
int length;
}SqList;
typedef SqList HeapType;
int compare=0;
int change=0;
int Create_Sq(SqList &L)
{
int i,k;
printf("请输入产生随机数的个数:");
scanf("%d",&k);//cin>>k;
L.length=k;
for(i=1;i<=k;++i)
{

L.r[i].key=rand();
}
return 1;
}

void InsertSort(SqList &L)
{ //直接插入排序
int i,j;
cout<<endl;
for(i=2;i<=L.length;++i)
if(LS(L.r[i].key,L.r[i-1].key))
{
++compare;
++change;
L.r[0]=L.r[i];
L.r[i]=L.r[i-1];
for(j=i-2;LS(L.r[0].key,L.r[j].key);--j)
{
++compare;
L.r[j+1]=L.r[j];
}
L.r[j+1]=L.r[0];
}
for(i=1;i<=L.length;i++)
cout<<" "<<L.r[i].key;
printf("-----插入排序后的序列-----\n");
printf("插入排序的比较次数:");
printf("%d\n",compare);//cout<<compare<<endl;
printf("\n插入排序的交换次数:");
printf("%d\n",change);//cout<<change<<endl;
compare=0;
change=0;
}

void main()
{
int i;
int dlta[MAXSIZE];
SqList L;
Create_Sq(L);
printf("-----待排序序列为-----\n");
//Create_Sq(L);
for(i=1;i<=L.length;i++)
cout<<" "<<L.r[i].key;
//SqList L2=L;
InsertSort(L);
}
...全文
3543 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
fuqinyijiu 2010-12-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hnuqinhuan 的回复:]
fflush(stdin);//清楚缓存
printf("\n");//换行

cout << endl;有刷新缓冲区的作用 和 换行的作用
[/Quote]
是这个,
wyget 2010-12-14
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 dieyingao 的回复:]

引用 2 楼 hnuqinhuan 的回复:

fflush(stdin);//清楚缓存
printf("\n");//换行

++
[/Quote]

yiruirui0507 2010-12-14
  • 打赏
  • 举报
回复
其实C中的'\n'也就是换行也有清空缓冲区的作用的
yiruirui0507 2010-12-14
  • 打赏
  • 举报
回复
fflush(stdin);//清楚缓存
printf("\n");//换行

cout << endl;有刷新缓冲区的作用 和 换行的作用

细节问题!
dieyingao 2010-12-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hnuqinhuan 的回复:]

fflush(stdin);//清楚缓存
printf("\n");//换行
[/Quote]
++
就想叫yoko 2010-12-14
  • 打赏
  • 举报
回复
貌似printf("\n");也是有刷新缓冲区的作用吧
screwzm 2010-12-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hnuqinhuan 的回复:]

fflush(stdin);//清楚缓存
printf("\n");//换行

cout << endl;有刷新缓冲区的作用 和 换行的作用
[/Quote]
+
xiakewudixl 2010-12-14
  • 打赏
  • 举报
回复
长知识
無_1024 2010-12-14
  • 打赏
  • 举报
回复

#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#define LS(a,b) ((a)<(b))
#define LL(a,b) ((a)>(b))
#define MAXSIZE 30000
typedef int KeyType;
typedef struct
{
int key;
}RedType;

typedef struct
{
RedType r[MAXSIZE+1];
int length;
}SqList;

typedef SqList HeapType;

int compare=0;
int change=0;
int Create_Sq(SqList &L)
{
int i,k;
printf("请输入产生随机数的个数:");
scanf("%d",&k);//cin>>k;
L.length=k;
for(i=1;i<=k;++i)
{
L.r[i].key=rand();
}
return 1;
}

void InsertSort(SqList &L)
{ //直接插入排序
int i,j;
fflush(stdin);
printf("\n");//----------
for(i=2;i<=L.length;++i)
if(LS(L.r[i].key,L.r[i-1].key))
{
++compare;
++change;
L.r[0]=L.r[i];
L.r[i]=L.r[i-1];
for(j=i-2;LS(L.r[0].key,L.r[j].key);--j)
{
++compare;
L.r[j+1]=L.r[j];
}
L.r[j+1]=L.r[0];
}
for(i=1;i<=L.length;i++)
printf("%d ",L.r[i].key);//---------
//cout<<" "<<L.r[i].key;
printf("\n-----插入排序后的序列-----\n");
printf("插入排序的比较次数:");
printf("%d \n",compare);//cout<<compare<<endl;
printf("\n插入排序的交换次数:");
printf("%d \n",change);//cout<<change<<endl;
compare=0;
change=0;
}

void main()
{
int i;
int dlta[MAXSIZE];
SqList L;
Create_Sq(L);
printf("\n-----待排序序列为-----\n");
//Create_Sq(L);
for(i=1;i<=L.length;i++)
printf("%d ",L.r[i].key);//--------
//cout<<" "<<L.r[i].key;
//SqList L2=L;
InsertSort(L);
}
無_1024 2010-12-14
  • 打赏
  • 举报
回复
fflush(stdin);//清楚缓存
printf("\n");//换行

cout << endl;有刷新缓冲区的作用 和 换行的作用
茫茫大海 2010-12-14
  • 打赏
  • 举报
回复

printf("\n");

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧