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
/* 1. Class Constant : Lazy initialization is supported. Officially recommanded way */ | |
class Singleton { | |
static let shared = Singleton() | |
private init() { } // prevent creating another instances. | |
} | |
/* 2. Nested Struct : Workaround for the lack of static class constants in Swift 1.1 and earlier. still useful | |
in functions, where static constants and varialbles cannot be used. */ |
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
/* 1. Class Constant : Lazy initialization is supported. Officially recommanded way */ | |
class Singleton { | |
static let shared = Singleton() | |
private init() { } // prevent creating another instances. | |
} | |
/* 2. Nested Struct : Workaround for the lack of static class constants in Swift 1.1 and earlier. still useful | |
in functions, where static constants and varialbles cannot be used. */ |
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
// Node | |
var Node = function(key) { | |
this.key = key; | |
this.parent = null; | |
this.right = null; | |
this.left = null; | |
} | |
Node.prototype = { | |
getKey: function() { return this.key; } |
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
// Node | |
var Node = function(key) { | |
this.key = key; | |
this.next = null; | |
}; | |
Node.prototype = { | |
getKey: function() { return this.key; } | |
, | |
getNext: function() { return this.next; } |
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
// Node | |
var Node = function(key) { | |
this.key = key; | |
this.next = null; | |
this.prev = null; | |
}; | |
Node.prototype = { | |
getKey: function() { return this.key; } | |
, |
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
// Node | |
var Node = function(key) { | |
this.key = key; | |
this.next = null; | |
}; | |
Node.prototype = { | |
getKey: function() { return this.key; } | |
, | |
getNext: function() { return this.next; } |
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
var Deque = function() { | |
this.arr = []; | |
}; | |
Deque.prototype.size = function() { | |
return this.arr.length; | |
}; | |
Deque.prototype.empty = function() { | |
return this.size() === 0; |
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
var Queue = function() { | |
this.data = []; | |
}; | |
Queue.prototype.size = function() { | |
return this.data.length; | |
} | |
Queue.prototype.empty = function() { | |
return this.size() === 0; |
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
var Stack = function() { | |
this.data = []; | |
}; | |
Stack.prototype.size = function() { | |
return this.data.length; | |
}; | |
Stack.prototype.empty = function() { | |
return this.size() === 0; |