MINA B
شنبه 01 آذر 1393, 00:26 صبح
سلام دوستان من یه کد مرتب سازی نوشتم اما چون دارم نیمی از آرایه ی مرتب شده رو به خود آرایه انتقال میدم و بعد به یک آرایه جدا کد درست عمل نمی کنه .میشه خواهش کنم بگید چطوری نیمه ای از آرایه رو که مرتب کردم مستقیما (یعنی توی کد sort) به آرایه half1 انتقال بدم؟ممنون.
#include <cstdlib>
#include <stdio.h>
using namespace std;
//int n; /*size of array*/
#define n 5
int arrayA[n]={6,4,7,2,1};
int half1[n];
void sort1(int a,int b);
int main()
{
int start=0;
int end=(n/2)-1;
sort1(start,end);
for(int i=0;i<n;i++)
{cout<<half1[i];}
}
void sort1(int a,int b)
{
int s = a;
int e = b;
int temp;
for(int i=e-1;i>1;i--)
{
for(int j=s;j<i;j++)
{
if(arrayA[j]>arrayA[j+1])
{
temp = arrayA[j];
arrayA[j] = arrayA[j+1];
arrayA[j+1] = temp;
}
}
}
for(int t=s;t<e;t++)
{
half1[t]=arrayA[t];
}
}
این راهم امتحان کردم
#include <iostream>
#include <cstdlib>
#include <stdio.h>
using namespace std;
//int n; /*size of array*/
#define n 10
int arrayA[n]={6,4,7,2,1,3,9,8,5,0};
int half1[n];
void sort1(int a,int b);
int main()
{
int start=0;
int end=(n/2)-1;
sort1(start,end);
for(int i=0;i<n;i++)
{cout<<half1[i];}
}
void sort1(int a,int b)
{
int s = a;
int e = b;
int temp;
for(int t=s;t<e;t++)
{
half1[t]=arrayA[t];
}
for(int i=e-1;i>1;i--)
{
for(int j=s;j<i;j++)
{
if(half1[j]>half1[j+1])
{
temp = half1[j];
half1[j] = half1[j+1];
half1[j+1] = temp;
}
}
}
}
اما جواب نداد.لطفا کمک.
#include <cstdlib>
#include <stdio.h>
using namespace std;
//int n; /*size of array*/
#define n 5
int arrayA[n]={6,4,7,2,1};
int half1[n];
void sort1(int a,int b);
int main()
{
int start=0;
int end=(n/2)-1;
sort1(start,end);
for(int i=0;i<n;i++)
{cout<<half1[i];}
}
void sort1(int a,int b)
{
int s = a;
int e = b;
int temp;
for(int i=e-1;i>1;i--)
{
for(int j=s;j<i;j++)
{
if(arrayA[j]>arrayA[j+1])
{
temp = arrayA[j];
arrayA[j] = arrayA[j+1];
arrayA[j+1] = temp;
}
}
}
for(int t=s;t<e;t++)
{
half1[t]=arrayA[t];
}
}
این راهم امتحان کردم
#include <iostream>
#include <cstdlib>
#include <stdio.h>
using namespace std;
//int n; /*size of array*/
#define n 10
int arrayA[n]={6,4,7,2,1,3,9,8,5,0};
int half1[n];
void sort1(int a,int b);
int main()
{
int start=0;
int end=(n/2)-1;
sort1(start,end);
for(int i=0;i<n;i++)
{cout<<half1[i];}
}
void sort1(int a,int b)
{
int s = a;
int e = b;
int temp;
for(int t=s;t<e;t++)
{
half1[t]=arrayA[t];
}
for(int i=e-1;i>1;i--)
{
for(int j=s;j<i;j++)
{
if(half1[j]>half1[j+1])
{
temp = half1[j];
half1[j] = half1[j+1];
half1[j+1] = temp;
}
}
}
}
اما جواب نداد.لطفا کمک.