程序语言中 tmp ans len beg 是什么意思?
发布网友
发布时间:2024-09-17 09:27
我来回答
共2个回答
热心网友
时间:2024-09-29 02:49
姐..电脑我也懂点..你直说程序语言..是电脑程序还是手机程序语言啊..说明白点咯..电脑程序语言也分很多种的啊..郁闷 人家不会加你的..这个东西不是三言2语说的明白的..你去下载个学习教材来慢慢看看先咯
热心网友
时间:2024-09-29 02:51
#include <stdio.h>
#include <stdlib.h>
inline void Swap(int* lhs, int* rhs)
{
int tmp = *lhs;
*lhs = *rhs;
*rhs = tmp;
}
void Reverse(int* beg, int* end)
{
while(beg < end)
Swap(beg++, --end);
}
void Print(int* beg, int* end)
{
while(beg != end)
printf("%d ", *beg++);
putchar('\n');
}
inline int Cmp(const void* lhs, const void* rhs)
{
return *(const int*)rhs - *(const int*)lhs;
}
void Permutation(int* beg, int* mid, int* end)
{
if(end- mid > 1)
qsort(mid, end - mid, sizeof(int), Cmp);
int* nav = end - 1;
Print(beg, mid);
for(;;)
{
int* tmp = nav;
if(*--nav < *tmp)
{
int* rmbt = end;
while(*--rmbt <= *nav);
Swap(nav, rmbt);
if(tmp <= mid)
{
Reverse(tmp, end);
if(end - mid > 1)
qsort(mid, end - mid, sizeof(int), Cmp);
}
Print(beg, mid);
nav = end - 1;
}
if(nav == beg)
{
Reverse(beg, mid);
break;
}
}
}
int main()
{
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int m, n;
printf("Select n numbers\b\b\b\b\b\b\b\b\b");
scanf("%d", &n);
printf("from m numbers\b\b\b\b\b\b\b\b\b");
scanf("%d", &m);
Permutation(a, a + n, a + m);
}
Select 3 numbers
from 3 numbers
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
Select 2 numbers
from 3 numbers
1 2
1 3
2 1
2 3
3 1
3 2
热心网友
时间:2024-09-29 02:49
姐..电脑我也懂点..你直说程序语言..是电脑程序还是手机程序语言啊..说明白点咯..电脑程序语言也分很多种的啊..郁闷 人家不会加你的..这个东西不是三言2语说的明白的..你去下载个学习教材来慢慢看看先咯
热心网友
时间:2024-09-29 02:49
#include <stdio.h>
#include <stdlib.h>
inline void Swap(int* lhs, int* rhs)
{
int tmp = *lhs;
*lhs = *rhs;
*rhs = tmp;
}
void Reverse(int* beg, int* end)
{
while(beg < end)
Swap(beg++, --end);
}
void Print(int* beg, int* end)
{
while(beg != end)
printf("%d ", *beg++);
putchar('\n');
}
inline int Cmp(const void* lhs, const void* rhs)
{
return *(const int*)rhs - *(const int*)lhs;
}
void Permutation(int* beg, int* mid, int* end)
{
if(end- mid > 1)
qsort(mid, end - mid, sizeof(int), Cmp);
int* nav = end - 1;
Print(beg, mid);
for(;;)
{
int* tmp = nav;
if(*--nav < *tmp)
{
int* rmbt = end;
while(*--rmbt <= *nav);
Swap(nav, rmbt);
if(tmp <= mid)
{
Reverse(tmp, end);
if(end - mid > 1)
qsort(mid, end - mid, sizeof(int), Cmp);
}
Print(beg, mid);
nav = end - 1;
}
if(nav == beg)
{
Reverse(beg, mid);
break;
}
}
}
int main()
{
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int m, n;
printf("Select n numbers\b\b\b\b\b\b\b\b\b");
scanf("%d", &n);
printf("from m numbers\b\b\b\b\b\b\b\b\b");
scanf("%d", &m);
Permutation(a, a + n, a + m);
}
Select 3 numbers
from 3 numbers
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
Select 2 numbers
from 3 numbers
1 2
1 3
2 1
2 3
3 1
3 2