本文共 1704 字,大约阅读时间需要 5 分钟。
最后一例,搞得快。三天之内走了一次。。
下一步,面象对像的javascript编程。
function Dictionary(){ var items = {}; this.has = function (key) { return key in items; }; this.set = function(key, value){ items[key] = value; }; this.remove = function(key){ if (this.has(key)){ delete items[key]; return true; } return false; }; this.get = function(key){ return this.has(key) ? items[key] : undefined; }; this.values = function(){ var values = []; for(var k in items){ if (this.has(k)) { values.push(items[k]); } } return values; }; this.clear = function(){ items = {}; }; this.size = function(){ var count = 0; for (var prop in items){ if(items.hasOwnProperty(prop)){ ++count; } } return count; }; this.getItems = function(){ return items; };}function Queue() { var items = []; this.enqueue = function(element){ items.push(element); } this.dequeue = function(){ return items.shift(); } this.front = function(){ return items[0]; } this.isEmpty = function(){ return items.length == 0; } this.clear = function(){ items = []; } this.size = function(){ return items.length; } this.print = function(){ console.log(items.toString()); }}function Graph() { var vertices = []; var adjList = new Dictionary(); var initializeColor = function(){ var color = []; for (var i=0; i'; var neighbors = adjList.get(vertices[i]); //{11} for (var j=0; j
转载地址:http://btsza.baihongyu.com/