This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A common example of a functor in Scala is the Option type. | |
// In Scala, Option is a functor because it provides the map method, which allows you to | |
// apply a function to the value inside an Option while preserving its structure. | |
val someNumber: Option[Int] = Some(3) | |
val incremented: Option[Int] = someNumber.map(_ + 1) | |
println(incremented) // Value transformed while structure is preserved | |
// Similarly List is a Functor | |
val numbers = List(1, 2, 3) | |
val doubled = numbers.map(_ * 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SkipList { | |
data class Node<Value>(val id: Value, val children: MutableList<Node<Value>> = mutableListOf()) | |
abstract class Value<T>(val value: T) { | |
abstract fun distance(other: T): Int | |
} | |
class IntValue(id: Int) : Value<Int>(id) { | |
override fun distance(other: Int): Int = kotlin.math.abs(this.value - other) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DoublePointer { | |
String s; | |
public DoublePointer(String s){ | |
this.s = s; | |
} | |
} | |
public class IdentitySwitch { | |
public static void main(String[] args) { | |
DoublePointer dp = new DoublePointer("unchanged"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IdentitySwitch { | |
public static void main(String[] args) { | |
String s = "unchanged"; | |
System.out.println(s); | |
foo(s); | |
System.out.println(s); | |
} | |
public void foo(String s) { | |
s = "changed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String s1("1"); | |
String s2("2"); | |
cout << s1 << s2 << endl; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
protected int a; | |
public A() { | |
a = 10; | |
} | |
} | |
class B extends A { | |
private int b; | |
public B() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let me know if you see any mistakes!! | |
public class Rectangle { | |
private int length; | |
private int width; | |
public Rectangle() {} | |
public Rectangle(int width, int length) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
// Let me know if you find any mistakes!! | |
public class FinalReview { | |
public static void main(String[] args) { | |
System.out.println("Question 1:"); | |
List<String> list = new ArrayList<>(); | |
list.add("1"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StackExercises { | |
public static void main(String[] args) { | |
// Reverse | |
System.out.println("Reverse:"); | |
System.out.println( | |
"12345 => " + reverse("12345") + '\n' + | |
"randy => " + reverse("randy") + '\n' + | |
"2 => " + reverse("2") | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BigO { | |
// Big O notation is used in Computer Science to describe the performance or complexity of an algorithm. | |
// Big O specifically describes the worst-case scenario, and can be used to describe | |
// the execution time required or the space used | |
// O(1) describes an algorithm that will always execute in the same time (or space) | |
// regardless of the size of the input data set. | |
private String[] strings = { "", null }; |
NewerOlder