Skip to content

Instantly share code, notes, and snippets.

@marsikeda
Created March 15, 2018 01:35
Show Gist options
  • Save marsikeda/366c70942392f399dad0278301c989df to your computer and use it in GitHub Desktop.
Save marsikeda/366c70942392f399dad0278301c989df to your computer and use it in GitHub Desktop.
Midterm DSA
func first5 (input: [Int]) -> Int {
var evenArray: [Int] = []
for element in input {
if element % 2 == 0 {
evenArray.append(element)
}
}
if evenArray.count < 5 {
return input.reduce( 0, {$0 + $1})
}
var answerArray: [Int] = []
for index in 1...5 {
answerArray.append(evenArray[index])
}
return answerArray.reduce(0 , {$0 + $1})
}
class Node {
var key: Int
var next: Node?
init(key: Int) {
self.key = key
}
}
func sumNode (input: Node) -> Int {
return 0
}
//not sure
//Queues are structured such that the first job in is the first job out (or done/printed in this case). A stack would print the last job entered into it first. And a hashmap is a bit too elaborate for this job.
//A hashmap would be ideal as it pairs values and keys together, so the artist name could be the key and their albums could be the songs.
//An array, or more specifically, a Set would be the best for picking a name at random as the raffle numbers would be stored without an order and it would be easier to pick one at random (i.e., print out the set and pick the first one).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment