ruby_collections 0.0.4 → 0.0.5

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: 409e6c00234df5a85788da2274f54e15b8eb8d43
4
- data.tar.gz: 82b5595664dd34d7e9dc835c5c14360a60cb9734
3
+ metadata.gz: 7398054d1b760aabc43207861265e55fe82b4f92
4
+ data.tar.gz: 691f42570967b022e3f558f8e4713c0b036810c6
5
5
  SHA512:
6
- metadata.gz: 7379fdab9b3e7d305ef34ccf19b55f137c7f9bc953caa6eae409222657ff5dcb23c9e279295cb88f6c2c91cff98ff4f60369ecb0991ba9c029a946ebbcc44041
7
- data.tar.gz: 552ac15b5b92f7f852858e71c256fd3e2676a7f45cb1ce0c2792007de842080e5eb88a82f976e9dd97bb1846b7728560c4939d99c4db3372529ad0f1021e3797
6
+ metadata.gz: 6d23fc58a7e892a2b551745cc9a11c1a0071548a022aeb10b66b9691d9b7615a7cb7f240bc56c0f1c0ac9a4332b05b3d85fcade2acf75b331dc53ab249b5b65d
7
+ data.tar.gz: 2c8bb1e27007067a9e83ae8950900d9a431261c81b612cfa709cbf80d28e3194196afacf4724aa0c9293ac50c82dc96a4a34985905efdfcba93ebbeee7711fc2
data/README.md CHANGED
@@ -70,7 +70,7 @@ list = RubyCollections::LinkedList.new
70
70
 
71
71
  list.size # => 0
72
72
 
73
- list.top # => nil
73
+ list.header # => ""
74
74
 
75
75
  list.isEmpty? # => true
76
76
 
@@ -84,10 +84,18 @@ list.add(3,1) # => 3 (number of elements in list)
84
84
 
85
85
  list.to_s # => "[2, 3, 1]"
86
86
 
87
- list.remove(2) # => removes element at index 2
87
+ list.remove(2) # => 2 (removes element at index 2)
88
88
 
89
89
  list.to_s # => "[2, 3]"
90
90
 
91
+ list.get(1) # => 3 (returns element at index 1)
92
+
93
+ list.get(1).setNext(12) # => adds a new node after index 1 with value 12. list is now [2, 3, 12]
94
+
95
+ list.get(1).data = 5 # => changes the value at index 1. list is now [2, 5, 12]
96
+
97
+ list.get(1).getNext # => 12
98
+
91
99
  ```
92
100
 
93
101
  ## Development
@@ -7,15 +7,18 @@ module RubyCollections
7
7
  @top = nil
8
8
  end
9
9
 
10
- def isEmpty?
10
+ def empty?
11
11
  size.zero?
12
12
  end
13
13
 
14
+ def header
15
+ @top ? @top.to_s : nil
16
+ end
17
+
14
18
  def add(data, index = nil)
15
19
  return nil if index and index >= size
16
20
  if index
17
- new_node = Node.new data, nil
18
- get(index-1).setNext(new_node)
21
+ get(index-1).setNext(data)
19
22
  else
20
23
  node = Node.new(data, top)
21
24
  @top = node
@@ -37,6 +40,7 @@ module RubyCollections
37
40
  end
38
41
 
39
42
  def to_s
43
+ return "" if empty?
40
44
  data = []
41
45
  data << (node = top).data
42
46
  (size-1).times {data << (node = node.getNext).data}
@@ -55,8 +59,8 @@ module RubyCollections
55
59
  ObjectSpace._id2ref(@next)
56
60
  end
57
61
 
58
- def setNext(node)
59
- return if node.nil?
62
+ def setNext(data)
63
+ node = Node.new(data, nil)
60
64
  next_node_id = instance_variable_get(:@next)
61
65
  @next = node.object_id
62
66
  node.instance_variable_set(:@next, next_node_id)
@@ -69,5 +73,4 @@ module RubyCollections
69
73
  end
70
74
 
71
75
  end
72
-
73
76
  end
@@ -1,3 +1,3 @@
1
1
  module RubyCollections
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_collections
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vikash Vikram