Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix VerticalFlipper by Muhammad Syukran Ni'matullah (185150201111059) Teknik Informatika - E #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,92 @@
// Output: [[7, 8, 9],
// [4, 5, 6],
// [1, 2, 3]]
// Created by Muhammad Syukran Ni'matullah (185150201111059)
public class VerticalFlipper implements MatrixMapper {
}

@Override
public byte[][] test(byte[][] input) {

int totalX = input.length;
int totalY = input[0].length;
for (int y = 0; y < totalY; y++) {
for (int x = 0; x < totalX / 2; x++) {
byte tmp = input[totalX - x - 1][y];
input[totalX - x - 1][y] = input[x][y];
input[x][y] = tmp;
}
}
return input;

}

@Override
public short[][] test(short[][] input) {
int totalX = input.length;
int totalY = input[0].length;
for (int y = 0; y < totalY; y++) {
for (int x = 0; x < totalX / 2; x++) {
short tmp = input[totalX - x - 1][y];
input[totalX - x - 1][y] = input[x][y];
input[x][y] = tmp;
}
}
return input;
}

@Override
public int[][] test(int[][] input) {
int totalX = input.length;
int totalY = input[0].length;
for (int y = 0; y < totalY; y++) {
for (int x = 0; x < totalX / 2; x++) {
int tmp = input[totalX - x - 1][y];
input[totalX - x - 1][y] = input[x][y];
input[x][y] = tmp;
}
}
return input;
}

@Override
public long[][] test(long[][] input) {
int totalX = input.length;
int totalY = input[0].length;
for (int y = 0; y < totalY; y++) {
for (int x = 0; x < totalX / 2; x++) {
long tmp = input[totalX - x - 1][y];
input[totalX - x - 1][y] = input[x][y];
input[x][y] = tmp;
}
}
return input;
}

@Override
public float[][] test(float[][] input) {
int totalX = input.length;
int totalY = input[0].length;
for (int y = 0; y < totalY; y++) {
for (int x = 0; x < totalX / 2; x++) {
float tmp = input[totalX - x - 1][y];
input[totalX - x - 1][y] = input[x][y];
input[x][y] = tmp;
}
}
return input;
}

@Override
public double[][] test(double[][] input) {
int totalX = input.length;
int totalY = input[0].length;
for (int y = 0; y < totalY; y++) {
for (int x = 0; x < totalX / 2; x++) {
double tmp = input[totalX - x - 1][y];
input[totalX - x - 1][y] = input[x][y];
input[x][y] = tmp;
}
}
return input;
}
}