Skip to content

3.3.1 Linear Linked List function #2

@kenshih1989

Description

@kenshih1989

Was having few question regarding following functions:

  1. Confusing functions name
    The following 2 functions name quite confusing:
setNextNode<-function(llist){
  llist$nextnode
}
setNextElement<-function(llist){
  llist$element
}

The contents in those function were showing the nextnode and element of a linked list node.
Why need use "set" instead of show?
Some more, "showElement" instead of "setNextElement" would be better since it is showing the element?

  1. Unable to add element
addElement<-function(new, llist) 
{
  if (isEmpty(llist)) {
    llist<-linkedlist(new)
  } else
  {
    llist<-linkListNode(llist, new)
  }
  llist
}

linkListNode <- function(val, node=NULL) {
  llist <- new.env(parent=create_emptyenv())
  llist$element <- val
  llist$nextnode <- node
  class(llist) <- "linkList"
  llist
}

From the source code provided, I could not find a function call "linkedlist" ?
If the list is not empty, the previous list become a new element and "new" become next node?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions