Skip to main content

Posts

Showing posts from September, 2019

Scala language implementation of Bubble Sort

Introduction Bubble sort is the simplest sorting algorithm. It has the following steps a) Iterates through the list b) Compares the adjacent elements c) Swap the adjacent elements if they are in not in proper sorting order d) The list is traversed repeatedly unless the list is sorted Worst Complexity : O(n*n) Best Complexity    : O(n) Alternate name      : Sinking Sort Implementation package main.scala object BubbleSort { val array = Array(0,5,2,6,3,1) def main (args : Array[String] ) { print("Unsorted List ") println(array.toList) print("Ascending sorted List ") bubbleSortAscending; println(array.toList) bubbleSortDescending print("Descending sorted List ") println(array.toList) } def bubbleSortAscending { //in scala you can combine inner and outer loops, until does not include the last number for( i <- 0 until array.length; j <- 1 until array.le

Create New Scala sbt project for Eclipse

Introduction In this post, we will learn how to create a new Scala sbt project and convert it into the eclipse project. We will then import the project into eclipse Step 1 Open your user's home directory, on windows, it will be user directory\.sbt\1.0\ Step 2 Create a new directory by the name of plugins if one does not exist Step 3 Create a new file  plugins.sbt ( if one does not exist)   inside the plugins folder Step 4 Open the newly created file  plugins.sbt and add the following line addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4") Step 5 Open a Command prompt and create a new directory for your Scala project i.e. > mkdir FirstScalaEclipseProject Step 6 Move to the new directory > cd FirstScalaEclipseProject Step 7 Enter the following command > sbt reload (if the shell is not restarted) > sbt eclipse Step 8 Open the eclipse, Go to File -> Import -> Import Existing Proj