[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Can someone smart explain to my dumbass why my reverse array

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 57
Thread images: 4

File: Untitled.png (49KB, 838x620px) Image search: [Google]
Untitled.png
49KB, 838x620px
Can someone smart explain to my dumbass why my reverse array method will not work correctly
>>
>>58650627
declare temp outside of the for scope
>>
File: Untitled.png (7KB, 541x180px) Image search: [Google]
Untitled.png
7KB, 541x180px
>>58650666
Still the same output
>>
>>58650684
cast temp to float
>>
>>58650715
Wouldn't be possible, that would be an incompabitable type for double array to float
>>
>>58650749
you're mom is a double array
>>
>>58650627
Arrays are pass by value. Retard.
>>
>>58650807
(you)
>>
>>58650627
Take ReverseArray out of the for loop in main. Retard
>>
>>58650915
ding ding ding, you are the winner. But someone on /dpt/ helped me out. Here is your congratulatory (you) for trying
>>
>>58650915
>>58651179
it's pretty alarming what kind of nonsense everybody pointed out before this
>>
>>58650627
class Box{
double[] dataSet;
}

it's about when java uses copy of object and when it uses it's reference...
>>
>>58651283
No it's not.
>>
>>58651304
why is he even using for loop in main? and yes it creates copy off array and works on it in ReverseArray(double[] array)
>>
>>58651304
>Is Java “pass-by-reference” or “pass-by-value”?
http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value

You have to box your data to manipulate on the insides from other methods...
>>
>>58650627
The fuck. Why are you reversing for every item in the dataset
>>
>>58651383
Pass by reference would need a pointer, so I think that's why Java never implemented this
>>
>>58650627
So much wrong here,OP.

You're over complicating a really simple task, I doubt you need to worry about performance (to whatever it was you were aiming for) in a homework assignment, just correctness.

You need a function that takes an array and returns the reversed array. So much less code, also using a generic in the type signature allows the function to work for any type of array.

Here's it in Swift, because do your own homework.

//: Playground - noun: a place where people can play

import UIKit

// Truncated for sanity
let data = [4758.806, 5795.711, 5014.683, 7701.312, 3246.816, 6989.659, 5027.365, 7440.575, 3019.995, 7241.105, 7696.65]

func reversedArray<T>(array: [T]) -> [T] {

var reversed = [T]()

for item in array {
reversed.insert(item, at: 0)
}

return reversed
}

print("There are \(data.count) items")

print("Reversed: \n \(reversedArray(array: data))")
>>
>>58651479
exactly, return new array, you would use c if it was about performance
>>
>>58650627
Collections.reverse(Arrays.asList(array));


Stop re-inventing the wheel anon.
>>
>>58651539
The point was obviously to invent some part of the wheel.
>>
>>58651479
"You are wrong OP, let me show you an example in this meme language you probably dont know".
>>
>>58651790
Write it in c then use jni to connect it to java.

Or do it objective style...
>>

int[] normal_array = { 0, 1, 2, 3 };

int[] reversed_array = new int[normal_array.lenght];

int position = normal_array.lenght;

for (int i = 0; i < normal_array.lenght; i++)
{
reversed_array[position] = normal_array[i];
position--;
}

>>
>>58651479
wow, Swift looks very similar to Python. Had no idea.
>>
File: 1484334193780.jpg (17KB, 256x352px) Image search: [Google]
1484334193780.jpg
17KB, 256x352px
>>58650627
>mfw people in this thread either can't reverse an array or have to write a ton of code to do it

dataset = [0, 1, 2, 3, 4]
dataset.reverse()
print(f'Reversed Array: {dataset}')


>mfw people call python a meme language because it allows you to get things done faster and with less code
>>
>>58652911
>"hey anon, for this assignment you have to write a function that reverses an array"
>wow im so smart, I'll use a premade function of the standard library
>>
>>58653034
>I'll roll the wheel down hill instead of trying to invent the wheel from scratch

That's right anon. While you're working on monotonous projects that were figured out 50 years ago, I'll be inventing new things and moving towards the future.
>>
>>58652911
>What is learning?
>>
>>58653452
are you literally stupid?

That's an ASSIGNMENT, but probably you don't even know what that is, right? Too much time living in your mother's basement
>>
>>58651861
>meme language
Safety isn't a meme anon
>>
>>58653548
>apple meme language
>is not a meme
>>
>>58653529
class Reverter{
double[] array;

Reverter(double[] array){
this.array = array;
}
void set(double[] array){
this.array = array;
}
void get(){
return array;
}
void reverse(){
for(int i=0; i<array.length-1; i++){
int tmp=array[i];
array[i]=array[array.length-1-i];
array[array.length-1-i]=tmp;
}
}

public static void main(String... arg){
Reverter opIsFag = new Reverter({1,2,3});
opIsFag.revert();
System.out.println(opIsFag.get());
}
}


here you fucking piece of shit
>>
>>58653558
Okay, so serious question what complaints do you have against Swift?
>>
>>58653688
disgusting
>>
>>58653747
show better
>>
>>58653761
you wrote a class, with 1 field in it and 1 useful method in it. Why.
>>
>>58653796
Show a better way for doing it in fucking java.
>>
File: oprah.gif (2MB, 440x248px) Image search: [Google]
oprah.gif
2MB, 440x248px
>>58653529
>are you stupid
>you living your mother's basement

Not an argument, try again anon.
>>
>>58653812
OP's broken way is better than your way. You should feel ashamed.
>>
>>58653846
Do you even know java? You should kill yourself or write better code.
>>
>>58653823
>don't do what the assignment asked
>not stupid

pick one
>>
>>58653897
it wouldn't be stupid if assignment said just to revert in java... other annon btw
>>
>>58653925
WRITE reverse function in java, not USE premade function in java
>>
>>58653939
You've got to calm down dude. Your autism is showing.
>>
>>58653939
Op never said it, welcome back op. Dragon dildo up your ass might help.
>>
>>58653939
data = [1, 2, 3, 4, 5]

for item in data:
data.remove(item)
data.insert(0, item)

print(data)


python rules, java drools.
>>
>>58653987
Op, he's right, write it in python.
>>
>>58650627
You're reversing array on every iteration, dumbass.
>>
>>58651229
It's almost as if half of /g/ is only here for the circle jerk.
>>
>>58650627
First, put spaces around binary operators.

Then we'll talk.
>>
>>58653987
> O(N^2) reverse function

literally kill yourself
>>
My implementation is still the best one unless you're caring about a few nanoseconds of execution time

private int[] Revert(int[] dataset)
{
int[] temp = new int[dataset.lenght];

int position = dataset.lenght;

for(int i = 0; i < dataset.lenght; i++)
{
temp[position] = dataset[i];
position--;
}
return temp;
}
>>
>>58653688
holy shit, an entire class for a single function?

That's why people here hate OOP
>>
>>58657433
>lenght
>position is wrong
nice try though
>>
>>58657496
Just to spite this fag you should change the variable declaration over anything spelling related.
>>
>>58652710
because it's for stupid people
Thread posts: 57
Thread images: 4


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.