zadt 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db43fb9319e2b6c73ea120c94757c39d06988d8d
4
- data.tar.gz: f470b3aa44f5e0a9b7e057fbefdc69a9103e641c
3
+ metadata.gz: cbc3136e504bb61d48ef017ca9fc1ccf398d2fdb
4
+ data.tar.gz: be82f8e8688f3074e381a293fa1aea983587c994
5
5
  SHA512:
6
- metadata.gz: ccf89f6657fd21b44cda7372d8eef144b25574a61dc0ab7ae68b48672b03f88ff99f79f5088940dd534fd503b547d4d133503ed62bcc4199d963e951fa84c16e
7
- data.tar.gz: e45995f6e8a8f38170c87068d5df3b3fcb021bf52d71b70f9248fdccc138a0b357707be952b578ba73dbedcfb4ea20b814ce948eec8dc661b122998fb9bdf819
6
+ metadata.gz: 878cc14d73b9ac881fcc787d214c6541afc91990aa551df86692c1bd2dd2178a1288ab22806a6ca66768a3241b648b343e2104d07c397eb528a74ff5a67370dc
7
+ data.tar.gz: cf9047e02fa9921b30e7925c00a7700b30d4ce812c15e3d696f792f22309818b1864f63ff55f74fd933ec99a5e9f1d527770dd05b5101745a33543d7315badaa
data/.DS_Store ADDED
Binary file
@@ -0,0 +1,6 @@
1
+ require_relative 'zadt/AbstractDataTypes/ADT.rb'
2
+ require_relative 'zadt/AbstractDataTypes/Stack.rb'
3
+ require_relative 'zadt/AbstractDataTypes/Queue.rb'
4
+ require_relative 'zadt/AbstractDataTypes/StackQueue.rb'
5
+ require_relative 'zadt/AbstractDataTypes/MinMaxStack.rb'
6
+ require_relative 'zadt/AbstractDataTypes/MinMaxStackQueue.rb'
@@ -0,0 +1,15 @@
1
+ module Zadt
2
+ class ADT
3
+ def self.help
4
+ puts "Thank you for using Zagorski Advanced Data Types!"
5
+ puts "This package contains the following Array-like Data Types:"
6
+ puts "-Stack, a LIFO array with functions push and pop"
7
+ puts "-Queue, a FIFO array with functions enqueue and dequeue"
8
+ puts "-StackQueue, a Queue that is Stack-based (no real difference)"
9
+ puts "-MinMaxStack, a Stack that can return Min and Max in constant time"
10
+ puts "-MinMaxStackQueue, a Queue that can return Min and Max in constant time"
11
+ puts ""
12
+ puts "Each data type also has a help function. Type Zadt::Stack::help for a list of Stack functions, and so on."
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,74 @@
1
+ # A MinMaxStack is a stack that allows for Min and Max
2
+ # to be found in constant time, unlike a stack or
3
+ # array that generally takes linear time.
4
+ module Zadt
5
+ class MinMaxStack
6
+ def initialize
7
+ @values = []
8
+ end
9
+
10
+ def self.help
11
+ puts "Here are the functions for MinMaxStack:"
12
+ puts "push(value)"
13
+ puts "pop"
14
+ puts "peek"
15
+ puts "min"
16
+ puts "max"
17
+ puts "length"
18
+ puts "show"
19
+ puts "empty?"
20
+ end
21
+
22
+ def self.methods
23
+ self.help
24
+ end
25
+
26
+ def help
27
+ MinMaxStack.help
28
+ end
29
+
30
+ def methods
31
+ help
32
+ end
33
+
34
+ def push(val)
35
+ if @values.empty?
36
+ @values.push([val, val, val])
37
+ else
38
+ cur_min = @values.last[1]
39
+ cur_max = @values.last[2]
40
+ @values.push([val, [val, cur_min].min, [val, cur_max].max])
41
+ @values
42
+ end
43
+ end
44
+
45
+ def pop
46
+ @values.pop[0]
47
+ end
48
+
49
+ def peek
50
+ @values.last[0]
51
+ end
52
+
53
+ def min
54
+ @values.empty? ? "Empty" : @values.last[1]
55
+ end
56
+
57
+ def max
58
+ @values.empty? ? "Empty" : @values.last[2]
59
+ end
60
+
61
+ def length
62
+ @values.length
63
+ end
64
+
65
+ def show
66
+ showthis = []
67
+ @values.map{|value| value[0]}
68
+ end
69
+
70
+ def empty?
71
+ @values.empty?
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,81 @@
1
+ # A MinMaxStackQueue is a queue that allows for Min and Max
2
+ # to be found in constant time, unlike a queue or
3
+ # array that generally takes linear time. It does this
4
+ # because it's based on a MinMaxStack, which has this
5
+ # ability.
6
+ module Zadt
7
+ class MinMaxStackQueue
8
+ def initialize
9
+ @in = MinMaxStack.new
10
+ @out = MinMaxStack.new
11
+ end
12
+
13
+ def self.help
14
+ puts "Here are the functions for MinMaxStackQueue:"
15
+ puts "show"
16
+ puts "enqueue(value)"
17
+ puts "dequeue"
18
+ puts "min"
19
+ puts "max"
20
+ puts "length"
21
+ puts "empty?"
22
+ end
23
+
24
+ def self.methods
25
+ self.help
26
+ end
27
+
28
+ def help
29
+ MinMaxStackQueue.help
30
+ end
31
+
32
+ def methods
33
+ help
34
+ end
35
+
36
+ def show
37
+ @out.show.reverse + @in.show
38
+ end
39
+
40
+ def enqueue(val)
41
+ @in.push(val)
42
+ end
43
+
44
+ def dequeue
45
+ if @out.empty?
46
+ @in.length.times do
47
+ @out.push(@in.pop)
48
+ end
49
+ end
50
+ @out.pop
51
+ end
52
+
53
+ def min
54
+ if @in.empty?
55
+ @out.min
56
+ elsif @out.empty?
57
+ @in.min
58
+ else
59
+ [@in.min, @out.min].min
60
+ end
61
+ end
62
+
63
+ def max
64
+ if @in.empty?
65
+ @out.max
66
+ elsif @out.empty?
67
+ @in.max
68
+ else
69
+ [@in.max, @out.max].max
70
+ end
71
+ end
72
+
73
+ def length
74
+ @in.length + @out.length
75
+ end
76
+
77
+ def empty?
78
+ @in.empty? && @out.empty?
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,49 @@
1
+ module Zadt
2
+ class Queue
3
+ def initialize
4
+ @values = Array.new
5
+ end
6
+
7
+ def self.help
8
+ puts "Here are the functions for Queue:"
9
+ puts "show"
10
+ puts "enqueue(value)"
11
+ puts "dequeue"
12
+ puts "length"
13
+ puts "empty?"
14
+ end
15
+
16
+ def self.methods
17
+ self.help
18
+ end
19
+
20
+ def help
21
+ Queue.help
22
+ end
23
+
24
+ def methods
25
+ help
26
+ end
27
+
28
+ def show
29
+ @values
30
+ end
31
+
32
+ def enqueue(val)
33
+ @values.push(val)
34
+ @values
35
+ end
36
+
37
+ def dequeue
38
+ @values.shift
39
+ end
40
+
41
+ def length
42
+ @values.length
43
+ end
44
+
45
+ def empty?
46
+ @values.empty?
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,49 @@
1
+ module Zadt
2
+ class Stack
3
+ def initialize
4
+ @values = Array.new
5
+ end
6
+
7
+ def self.help
8
+ puts "Here are the functions for Stack:"
9
+ puts "show"
10
+ puts "push(value)"
11
+ puts "pop"
12
+ puts "length"
13
+ puts "empty?"
14
+ end
15
+
16
+ def self.methods
17
+ self.help
18
+ end
19
+
20
+ def help
21
+ Stack.help
22
+ end
23
+
24
+ def methods
25
+ help
26
+ end
27
+
28
+ def show
29
+ @values
30
+ end
31
+
32
+ def push(val)
33
+ @values.push(val)
34
+ @values
35
+ end
36
+
37
+ def pop
38
+ @values.pop
39
+ end
40
+
41
+ def length
42
+ @values.length
43
+ end
44
+
45
+ def empty?
46
+ @values.empty?
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,58 @@
1
+ # A StackQueue works just like a queue, but it's based on
2
+ # a Stack. Functionality-wise, it's exactly the same
3
+ # as a queue. I mainly made it as an exercise leading
4
+ # up to MinMaxStackQueue.
5
+ module Zadt
6
+ class StackQueue
7
+ def initialize
8
+ @in = Stack.new
9
+ @out = Stack.new
10
+ end
11
+
12
+ def self.help
13
+ puts "Here are the functions for StackQueue:"
14
+ puts "show"
15
+ puts "enqueue(value)"
16
+ puts "dequeue"
17
+ puts "length"
18
+ puts "empty?"
19
+ end
20
+
21
+ def self.methods
22
+ self.help
23
+ end
24
+
25
+ def help
26
+ StackQueue.help
27
+ end
28
+
29
+ def methods
30
+ help
31
+ end
32
+
33
+ def show
34
+ @out.show.reverse + @in.show
35
+ end
36
+
37
+ def enqueue(val)
38
+ @in.push(val)
39
+ end
40
+
41
+ def dequeue
42
+ if @out.empty?
43
+ @in.length.times do
44
+ @out.push(@in.pop)
45
+ end
46
+ end
47
+ @out.pop
48
+ end
49
+
50
+ def length
51
+ @in.length + @out.length
52
+ end
53
+
54
+ def empty?
55
+ @values.empty?
56
+ end
57
+ end
58
+ end
data/lib/zadt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Zadt
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/zadt.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "zadt/version"
2
+ require_relative "ADT_requireables.rb"
2
3
 
3
4
  module Zadt
4
5
  # Your code goes here...
data/zadt.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["benj@zagorski.com"]
11
11
 
12
12
  spec.summary = %q{Zagorski ADT is a collection of advanced data types that are not included in the standard Ruby library.}
13
- spec.description = %q{Includes the following Advanced Data Types: Stack, Queue, StackQueue, MinMaxStack, and MinMaxStackQueue.}
13
+ spec.description = %q{Includes the following Advanced Data Types: Stack, Queue, StackQueue, MinMaxStack, and MinMaxStackQueue. Once installed, type "Zadt::ADT::help" for a list of datatypes and basic functionality.}
14
14
  spec.homepage = "https://github.com/MrMicrowaveOven/zadt.git"
15
15
  spec.license = "MIT"
16
16
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zadt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Zagorski
@@ -53,13 +53,15 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  description: 'Includes the following Advanced Data Types: Stack, Queue, StackQueue,
56
- MinMaxStack, and MinMaxStackQueue.'
56
+ MinMaxStack, and MinMaxStackQueue. Once installed, type "Zadt::ADT::help" for a
57
+ list of datatypes and basic functionality.'
57
58
  email:
58
59
  - benj@zagorski.com
59
60
  executables: []
60
61
  extensions: []
61
62
  extra_rdoc_files: []
62
63
  files:
64
+ - ".DS_Store"
63
65
  - ".gitignore"
64
66
  - ".rspec"
65
67
  - ".travis.yml"
@@ -70,7 +72,14 @@ files:
70
72
  - Rakefile
71
73
  - bin/console
72
74
  - bin/setup
75
+ - lib/ADT_requireables.rb
73
76
  - lib/zadt.rb
77
+ - lib/zadt/AbstractDataTypes/ADT.rb
78
+ - lib/zadt/AbstractDataTypes/MinMaxStack.rb
79
+ - lib/zadt/AbstractDataTypes/MinMaxStackQueue.rb
80
+ - lib/zadt/AbstractDataTypes/Queue.rb
81
+ - lib/zadt/AbstractDataTypes/Stack.rb
82
+ - lib/zadt/AbstractDataTypes/StackQueue.rb
74
83
  - lib/zadt/version.rb
75
84
  - zadt.gemspec
76
85
  homepage: https://github.com/MrMicrowaveOven/zadt.git