odds to the first and evens last
Tag : c , By : cautionsign
Date : March 29 2020, 07:55 AM
may help you . I am trying to solve a problem like ... in an array we have to move all the odd elements to the start ...and even elements to the end ... i tried this way but evens lose order here ...can someone help me ??????? the output i get is ...1 3 5 7 9 4 8 2 6 , How about this solution #include<stdio.h>
int main()
{
int i;
int arr[]={ 2, 1 ,4 ,3 ,6 ,5 ,8 ,7 ,9};
int arr_size = sizeof(arr)/sizeof(arr[0]);
int sorted[arr_size];
int sp = 0;
for(i=0;i<arr_size;i++){
if(arr[i]&1){
sorted[sp++]=arr[i];
}
}
for(i=0;i<arr_size;i++){
if(!(arr[i]&1)){
sorted[sp++]=arr[i];
}
}
for(i=0;i< arr_size ;i++)
printf("%d ", sorted[i]);
return 0;
}
1 3 5 7 9 2 4 6 8
int main(){
int i;
int arr[]={ 2, 1 ,4 ,3 ,6 ,5 ,8 ,7 ,9};
int arr_size = sizeof(arr)/sizeof(arr[0]);
int sorted[arr_size];
int even = 1+arr_size/2;
int odd = 0;
for(i=0;i<arr_size;i++){
if(arr[i]&1)
sorted[odd++]=arr[i];
else
sorted[even++]=arr[i];
}
for(i=0;i< arr_size ;i++)
printf("%d ", sorted[i]);
return 0;
}
|
Relocate without relocate in subversion?
Tag : svn , By : Paul Schwarz
Date : March 29 2020, 07:55 AM
I hope this helps you . I need to switch the base URL of my working copy in subversion. , I found the answer I was looking for. It's just a matter of running svn switch --relocate OLD_URL NEW_URL
svn relocate NEW_URL
|
JavaFX - advised to move object using relocate(x,y) over setLayoutX(x) yet I can't modify relocate parameters
Tag : java , By : Josh Tegart
Date : March 29 2020, 07:55 AM
This might help you I've checked API how to change position of a graphical object. I used setLayoutX and setLayoutY successfully (it continously inkremented object x and y) yet they advised me to use relocate(x,y) instead. , I've solved the issue now. Code that solved it: double x=circle.getLayoutX();
double y=circle.getLayoutY();
x+=10;
y+=10;
circle.relocate(x,y);
|
From array of evens and odds make new array where evens first odds last
Date : March 29 2020, 07:55 AM
may help you . I have not seen where your problem come from. However, there is a much easier way to do this using std::sort. Here is how I would do it: #include <iostream>
#include <algorithm>
using namespace std;
bool sortingFunction(int left, int right)
{
if (left % 2 == 0 && right % 2 == 0 || left % 2 != 0 && right % 2 != 0)
return left<right;
else if (left % 2 != 0 && right % 2 == 0)
return false;
else if (left % 2 == 0 && right % 2 != 0)
return true;
}
int main()
{
int no;
cout << "Size of Array: ";
cin >> no;
int arr[no];
cout << "Enter any " << no << " elements in Array: ";
for (int i = 0; i<no;i++)
{
cin >> arr[i];
}
std::sort(arr,arr+no,sortingFunction);
for (int i = 0; i< no; i++)
cout<<arr[i]<<" ";
cout<<endl;
return 0;
}
|
The Little Schemer evens-only*&co
Date : March 29 2020, 07:55 AM
|