Skip to content

Instantly share code, notes, and snippets.

@btg5679
Created December 17, 2018 01:14
Show Gist options
  • Save btg5679/3f9b6899a712484fd226175a32febee3 to your computer and use it in GitHub Desktop.
Save btg5679/3f9b6899a712484fd226175a32febee3 to your computer and use it in GitHub Desktop.
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