3. Implement Lisp-like list in Java. Write basic operations such as 'car', 'cdr', and
'cons'. If L is a list [3, 0, 2, 5], L.car() returns 3, while L.cdr() returns [0,2,5].
ALGORITHM
STEP 1: Create a node of a list having data part and link part.
STEP 2: Create a menu having the following choices : insert, car, cdr, adjoin and
display.
STEP 3: Read the choice from the user and call the respective m ethods.
STEP 4: Create another class which implements the same interface to implement the
concept of stack through linked list.
INSERT
STEP 1: Create an object of node and append to the list.
CAR
STEP 1: Return the first node data.
CDR
STEP 1: Return all the node (data part) in the list except the first node.
ADJOIN
STEP 1: Check if the node to be inserted is already present in the list, if not present
append to the list.
0 comments:
Post a Comment