// Create a new ring of size 5
r := ring.New(5)
+ // Get the length of the ring
+ n := r.Len()
+
// Initialize the ring with some integer values
- for i := 0; i < r.Len(); i++ {
+ for i := 0; i < n; i++ {
r.Value = i
r = r.Next()
}
// Iterate through the ring and print its contents
- for j := 0; j < r.Len(); j++ {
+ for j := 0; j < n; j++ {
fmt.Println(r.Value)
r = r.Next()
}
// Create a new ring of size 5
r := ring.New(5)
+ // Get the length of the ring
+ n := r.Len()
+
// Initialize the ring with some integer values
- for i := 0; i < r.Len(); i++ {
+ for i := 0; i < n; i++ {
r.Value = i
r = r.Next()
}
// Iterate through the ring backwards and print its contents
- for j := 0; j < r.Len(); j++ {
+ for j := 0; j < n; j++ {
r = r.Prev()
fmt.Println(r.Value)
}
// Create a new ring of size 5
r := ring.New(5)
+ // Get the length of the ring
+ n := r.Len()
+
// Initialize the ring with some integer values
- for i := 0; i < r.Len(); i++ {
+ for i := 0; i < n; i++ {
r.Value = i
r = r.Next()
}
// Create a new ring of size 5
r := ring.New(5)
+ // Get the length of the ring
+ n := r.Len()
+
// Initialize the ring with some integer values
- for i := 0; i < r.Len(); i++ {
+ for i := 0; i < n; i++ {
r.Value = i
r = r.Next()
}
r := ring.New(2)
s := ring.New(2)
+ // Get the length of the ring
+ lr := r.Len()
+ ls := s.Len()
+
// Initialize r with 0s
- for i := 0; i < r.Len(); i++ {
+ for i := 0; i < lr; i++ {
r.Value = 0
r = r.Next()
}
// Initialize s with 1s
- for j := 0; j < s.Len(); j++ {
+ for j := 0; j < ls; j++ {
s.Value = 1
s = s.Next()
}
// Create a new ring of size 6
r := ring.New(6)
+ // Get the length of the ring
+ n := r.Len()
+
// Initialize the ring with some integer values
- for i := 0; i < r.Len(); i++ {
+ for i := 0; i < n; i++ {
r.Value = i
r = r.Next()
}