Created
December 17, 2018 01:14
-
-
Save btg5679/3f9b6899a712484fd226175a32febee3 to your computer and use it in GitHub Desktop.
This file contains 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
function TaskNode(task) { | |
this.taskName = task.name; | |
this.taskUri = task.id | |
this.nextTask = null; | |
this.previousTask = null; | |
} | |
function WorkflowTaskLinkedList() { | |
this.head = new TaskNode({name:"head",id:'http://123'}); | |
this.find = find; | |
this.insert = insert; | |
this.remove = remove; | |
this.findLast = findLast; | |
} | |
function findLast() { | |
var currNode = this.head; | |
while (!(currNode.nextTask == null)) { | |
currNode = currNode.nextTask; | |
} | |
return currNode; | |
} | |
function remove(item) { | |
var currNode = this.find(item); | |
if (!(currNode.next == null)) { | |
currNode.previousTask.nextTask = currNode.nextTask; | |
currNode.nextTask.previousTask = currNode.previousTask; | |
currNode.nextTask = null; | |
currNode.previousTask = null; | |
} | |
} | |
function find(item) { | |
var currNode = this.head; | |
while (currNode.taskName != item.name) { | |
currNode = currNode.nextTask; | |
} | |
return currNode; | |
} | |
function insert(newTask, item) { | |
var newNode = new TaskNode(newTask); | |
var current = this.find(item); | |
newNode.nextTask = current.nextTask; | |
newNode.previousTask = current; | |
current.nextTask = newNode; | |
} | |
var tasks = new WorkflowTaskLinkedList(); | |
tasks.insert({name:"C",id:"http://456"}, {name:"head"}); | |
console.log(tasks.find({name:"C"})) | |
console.log(JSON.stringify(tasks.head)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment