OBJECTIVE |
---|
We will use the concepts discussed in client-server model and request-response handling in a simple web application, use our first web application framework, and be able to build a simple web application. |
Self-Assesment |
---|
# Classes and Objects | |
## Code Along | |
story_hash = { | |
"question" => "Welcome to the haunted hotel. What room would you like to go into?", | |
"room 1" => "you're dead", | |
"room 2" => { "question" => "You picked a good room. What would like to do?", | |
"sleep" => "You're rested for the morning", |
#takes two squares | |
def check_square(square) | |
if(square[0][0] > square[1][0]) | |
puts square | |
square[0][0], square[1][0] = square[1][0], square[0][0] | |
end |
class BinTree | |
attr_accessor :left, :right, :val | |
def initialize(val) | |
@left = nil | |
@right = nil | |
@val = val | |
end |
class BinTree | |
attr_accessor :left, :right, :val | |
def initialize(val) | |
@left = nil | |
@right = nil | |
@val = val | |
end |
1.) Write a function called last
that finds the last node in the list.
2.) Write a function called count
that gets the length of linked list. Don't use the #count
method.
3.) Write a function called average
that sums a linked list of numbers and divides it by the length.
4.) Write a function to reverse
a linked list.
### | |
# Node List | |
### | |
class Node | |
attr_accessor :val, :next | |
def initialize(val, next_ref =nil) | |
@val=val | |
@next=next_ref | |
end |
### | |
# Node List | |
### | |
class Node | |
attr_accessor :val, :next | |
def initialize(val,next=nil) | |
@val=val | |
@next=next | |
end |
class Node | |
attr_accessor :data, :next | |
def initialize(data=nil) | |
@data = data | |
end | |
end |