diff --git a/AMDLinkedList.js b/AMDLinkedList.js index 28d2b1e..06a68e7 100644 --- a/AMDLinkedList.js +++ b/AMDLinkedList.js @@ -2,7 +2,7 @@ * LinkedList for JavaScript. * Eventually this will completely emulate a regular Java linked list. * Copyright 2013, Brian Milton - * Version: 0.38.2 (22nd July 2013) + * Version: 0.38.3 (22nd July 2013) */ define("LinkedList", function() { @@ -116,13 +116,12 @@ define("LinkedList", function() { if(this._length === 0) { return; } - var head = this._head; - var tail = this._tail; - head.data = null; - head.next = null; - tail.data = null; + var node = {data:null,next:null} + this._head = null; + this._tail = null; this._length = 0; MODCOUNT++; + return; }; /* @@ -501,7 +500,8 @@ define("LinkedList", function() { if(current.next !== null) { var nextNode = current.next; // If not, apply the function passed on this and the next node. - if(sortFunction(current.data,nextNode.data)) { + var sortResult = sortFunction(current.data,nextNode.data); + if(sortResult === true || sortResult > 0) { // Result of the function is true... // Sort isn't complete (nextNode is not null) sortDone = false; diff --git a/LinkedList.js b/LinkedList.js index 32529a7..9b48494 100644 --- a/LinkedList.js +++ b/LinkedList.js @@ -2,7 +2,7 @@ * LinkedList for JavaScript. * Eventually this will completely emulate a regular Java linked list. * Copyright 2013, Brian Milton - * Version: 0.38.2 (22nd July 2013) + * Version: 0.38.3 (22nd July 2013) */ (function() { @@ -116,13 +116,12 @@ if(this._length === 0) { return; } - var head = this._head; - var tail = this._tail; - head.data = null; - head.next = null; - tail.data = null; + var node = {data:null,next:null} + this._head = null; + this._tail = null; this._length = 0; MODCOUNT++; + return; }; /* @@ -501,7 +500,8 @@ if(current.next !== null) { var nextNode = current.next; // If not, apply the function passed on this and the next node. - if(sortFunction(current.data,nextNode.data)) { + var sortResult = sortFunction(current.data,nextNode.data); + if(sortResult === true || sortResult > 0) { // Result of the function is true... // Sort isn't complete (nextNode is not null) sortDone = false; diff --git a/LinkedList.min.js b/LinkedList.min.js new file mode 100644 index 0000000..5e44835 --- /dev/null +++ b/LinkedList.min.js @@ -0,0 +1,2 @@ +/* JSLinkedList v0.38.3 (c) 2013, Pachi Systems Inc / Brian Milton */ +(function(){var a=0;function b(){this._length=0;this._head=null;this._tail=null}b.prototype.add=function(c,e){if(e){var g={data:e,next:null};var h=this._head;var d=0;var f;if(c>-1&&c-1&&c-1&&c0){f=false;g=h.data;h.data=c.data;c.data=g}}h=h.next}while(h!==null);h=this._tail}a++;return true}};b.prototype.sortedAdd=function(e,c){var g={data:e,next:null};if(this._length===0){this._head=g;this._tail=g;a++;this._length++;return}var j=this._head;var h=h||"asc";var f=null;var d=0;while(d++