不能
用链表 字符串 动态申请内存
代码:
typedef struct St_1
{
char *cData;
St_1 *pNext;
}
使用时候 HeapAlloc 大小为sizeof(St_1)+X //X为你希望第一的大小
cData指向X内存
然后用pNext把整个数据都链起来!!! 排序就不用说了吧
OK 搞定
请使用下面的代码:
要按自定义的大小排序,只需修改CompareStr()
#include
#include
#include
#include
using namespace std;
typedef vector
bool CompareStr( const string s1, const string s2 )
{
if( s1 > s2 ) return true;
else return false;
}
void main()
{
int n = 6;
int i;
StringVector sv;
string str[]={"ag","vg","bh","ji","ks","pw"};
for( i=0; i
sort( sv.begin(), sv.end(), CompareStr );
// output to see we are right.
for( i=0; i
for( i=0; i
str[i] = sv[i];
}
// output to see we are still right.
for( i=0; i
运行结果:
vg
pw
ks
ji
bh
ag
vg
pw
ks
ji
bh
ag
Press any key to continue
char str[]={……}你想说的是这样吧。
请使用下面的代码:
要按自定义的大小排序,只需修改CompareStr()
#include
#include
#include
#include
using
namespace
std;
typedef
vector
StringVector;
bool
CompareStr(
const
string
s1,
const
string
s2
)
{
if(
s1
>
s2
)
return
true;
else
return
false;
}
void
main()
{
int
n
=
6;
int
i;
StringVector
sv;
string
str[]={"ag","vg","bh","ji","ks","pw"};
for(
i=0;
i
评论
0
0
加载更多
#include
void
sort_arry_str(char
str[])
{
char
ch;
if(str[0]
>
str[1])
{
ch
=
str[0],str[0]
=
str[1],str[1]
=
ch;
}
if(str[0]
>
str[2])
{
ch
=
str[0],str[0]
=
str[2],str[2]
=
ch;
}
if(str[1]
>
str[2])
{
ch
=
str[1],str[1]
=
str[2],str[2]
=
ch;
}
printf("%c
%c
%c\n",str[0],str[1],str[2]);
}
int
main(void)
{
char
str[4];
gets(str);
sort_arry_str(str);
return
0;
}