How to create a node for a linked list?

how to create a node for a linked list?
class Node
attr_accessor :value, :next

def initialize(value, nex)
@value = value
@next = nex
end
end
class LinkedList
attr_accessor :node

def push(value: nil, nex: nil)
@node = Node.new(value, nex)
end
end
  1. attr_accessor :node
  2. instance method push
class Node
attr_accessor :value, :next

def initialize(value, nex)
@value = value
@next = nex
end
end
class LinkedList
attr_accessor :node

def push(value: nil, nex: nil)
@node = Node.new(value, nex)
end
end

# Created object of LinkedList
linked_list = LinkedList.new
p linked_list.push(value: 2)
p linked_list.push(value: 1)

--

--

--

Hello i am prateek vyas working as a ruby developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Make Your MacOS Terminal Look as Awesome as Mine in 2021

Working with Partners to Expand Customer Horizons

How to create integration workflow for online stores with Azure Logic Apps

Lambdas vs Local Functions What’s the Difference

What the *$@% is Docker for the Beginner Programmer (Part 1): Virtual Environments

BLUETOOTH CONTROLLED RC BOT

Image of my Bluetooth RC Controlled Car

What I’d Change, Keep the Same, & Don’t Yet Know

[Tech] Logging Patterns

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prateek vyas

Prateek vyas

Hello i am prateek vyas working as a ruby developer

More from Medium

Quick Guide to Nested Attributes in Rails

Each Method in Ruby

User Auth and Password Protection: Rails

Model View Controller: How to Use the MVC Architecture to Achieve Separation of Concerns