Skip to content

Commit ed86c63

Browse files
Added reverse array solution
1 parent 8fa979b commit ed86c63

File tree

8 files changed

+140
-1
lines changed

8 files changed

+140
-1
lines changed

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
*.class
2+
*.log
3+
4+
# sbt specific
5+
.cache
6+
.history
7+
.lib/
8+
.idea/
9+
dist/*
10+
target/
11+
build/
12+
node_modules/
13+
lib_managed/
14+
src_managed/
15+
project/boot/
16+
project/plugins/project/
17+
18+
# Scala-IDE specific
19+
.scala_dependencies
20+
.worksheet

.travis.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: scala
2+
jdk:
3+
- oraclejdk8
4+
dist: trusty
5+
env:
6+
global:
7+
- TRAVIS_SBT_VERSION="1.2.8"
8+
script:
9+
- sbt test
10+
cache:
11+
directories:
12+
- "$HOME/.ivy2/cache"
13+
- "$HOME/.sbt"
14+
before_cache:
15+
# Cleanup the cached directories to avoid unnecessary cache updates
16+
- find $HOME/.ivy2/cache -name "ivydata-*.properties" -print -delete
17+
- find $HOME/.sbt -name "*.lock" -print -delete

README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1-
# data-algorithms
1+
2+
[![Build Status](https://travis-ci.org/viktor-podzigun/data-algorithms.svg?branch=master)](https://travis-ci.org/viktor-podzigun/data-algorithms)
3+
4+
## data-algorithms
25
My solutions to different data structures and algorithms problems
6+
7+
### How to build/run it
8+
9+
To build and run all tests use the following command:
10+
```bash
11+
sbt test
12+
```
13+
14+
### Overview
15+
16+
* Arrays
17+
* [ReverseArray](src/main/java/algorithms/array/ReverseArray.java) => [test](src/test/scala/algorithms/array/ReverseArraySpec.scala)

build.sbt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
val ideExcludedDirectories = SettingKey[Seq[File]]("ide-excluded-directories")
3+
4+
lazy val `elevator-challenge` = (project in file("."))
5+
.settings(
6+
organization := "org.scommons.viktor-podzigun",
7+
name := "data-algorithms",
8+
description := "My solutions to different data structures and algorithms problems",
9+
scalaVersion := "2.12.10",
10+
scalacOptions ++= Seq(
11+
//see https://docs.scala-lang.org/overviews/compiler-options/index.html#Warning_Settings
12+
//"-Xcheckinit",
13+
"-Xfatal-warnings",
14+
"-Xlint:_",
15+
"-Ywarn-macros:after", // Only inspect expanded trees when generating unused symbol warnings
16+
"-explaintypes",
17+
"-unchecked",
18+
"-deprecation",
19+
"-feature"
20+
),
21+
22+
ideExcludedDirectories := {
23+
val base = baseDirectory.value
24+
List(
25+
base / ".idea",
26+
base / "target"
27+
)
28+
},
29+
30+
libraryDependencies ++= Seq(
31+
"org.scalatest" %% "scalatest" % "3.0.1" % "test"
32+
),
33+
34+
//when run tests with coverage: "sbt clean coverage test coverageReport"
35+
coverageMinimum := 80
36+
)

project/build.properties

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.2.8

project/plugins.sbt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
3+
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.4")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package algorithms.array;
2+
3+
public class ReverseArray {
4+
5+
public static int[] reverse(int[] arr) {
6+
for (int i = 0, j = arr.length - 1; i < j; i++, j--) {
7+
int tmp = arr[i];
8+
arr[i] = arr[j];
9+
arr[j] = tmp;
10+
11+
//printArray(arr);
12+
}
13+
14+
return arr;
15+
}
16+
17+
static void printArray(int[] arr) {
18+
StringBuilder sb = new StringBuilder("[");
19+
for (int i = 0; i < arr.length; i++) {
20+
if (i > 0) {
21+
sb.append(", ");
22+
}
23+
24+
sb.append(arr[i]);
25+
}
26+
27+
sb.append("]");
28+
System.out.println(sb.toString());
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package algorithms.array
2+
3+
import org.scalatest.{FlatSpec, Matchers}
4+
5+
class ReverseArraySpec extends FlatSpec with Matchers {
6+
7+
it should "reverse the whole array" in {
8+
//given
9+
val arr = Array(1, 2, 3, 4, 5)
10+
11+
//when
12+
val result = ReverseArray.reverse(arr)
13+
14+
//then
15+
result.toList shouldBe List(5, 4, 3, 2, 1)
16+
}
17+
}

0 commit comments

Comments
 (0)