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
    
  
  
    
  | class Node | |
| attr_accessor :value, :next | |
| def initialize(value, next_node) | |
| @value = value | |
| @next = next_node | |
| end | |
| end | 
  
    
      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
    
  
  
    
  | class LinkedList | |
| class Node | |
| attr_accessor :value, :next | |
| def initialize(value, next_node) | |
| @value = value | |
| @next = next_node | |
| end | |
| end | |
| def initialize(value) | 
  
    
      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
    
  
  
    
  | def insert(value) | |
| @head = Node.new(value, nil) || return if @head.nil? | |
| current = @head | |
| # Traverse to the end of the list from the head node | |
| while current.next | |
| current = current.next | |
| end | |
| # Initialize a new node and append to the current last node | |
| current.next = Node.new(value, nil) | |
| end | 
  
    
      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
    
  
  
    
  | def delete(value) | |
| (puts "List is Empty") || return if @head.nil? | |
| current = @head | |
| if current.value.eql?(value) | |
| # If first node is the deletion value assign head to next node | |
| @head = current&.next | |
| else | |
| while current.next && (current.next.value != value) | |
| current = current.next | |
| end | 
  
    
      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
    
  
  
    
  | def search(value) | |
| (puts "List is Empty") || return if @head.nil? | |
| current = @head | |
| while current.next | |
| (element_found = true) && break if current.value.eql?(value) | |
| current = current.next | |
| end | |
| # Check if searched value is already found or is the last element | |
| (element_found || current.value.eql?(value)) ? (puts "Element found") : (puts "Element not present") | |
| end | 
  
    
      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
    
  
  
    
  | def print_list | |
| (puts "List is Empty") || return if @head.nil? | |
| current = @head | |
| while current.next | |
| print "#{current.value} ->" | |
| current = current.next | |
| end | |
| print "#{current.value}" | |
| end | 
  
    
      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
    
  
  
    
  | class LinkedList | |
| class Node | |
| attr_accessor :value, :next | |
| def initialize(value, next_node) | |
| @value = value | |
| @next = next_node | |
| end | |
| end |