
2算法思想描述:2.1算法概述:建立一个循环单链表,然后输入要建立结点的个数,在每个结点输入一个密码,同时按输入时的顺序进行编号:1,2,3,4, ……n.任选一个正整数x作为初始报数上限值.从定义的那个头结点开始,数到x,输出该结点所储存的编号和密码.并将该密码作为新的x值,同时还将该密码所在的结点删除.如此循环链表还剩最后一个数据的时候停止此循环.再将最后一个没在循环里面的编号和密码另外输出.循环链表如图1所示:图22.2算法具体分析window ,switch ,upbar(), downbar(),key 这几个函数是构建本程序菜单所必须的函数.window 用于开窗口,以坐标的形式开辟一个窗口,并且可以在窗口里面储存数据.switch 创建菜单选项,key 主要用于获取键盘上的字符 包括字母和方向键,enter键 ,upbar 和 downbar 实现光条的上移和下移. textbackground ,textcolor 。(2) 线性表adt顺序存储实现中的创建、查找、插入和删除等基本操作及相关算法,线性表adt链式存储实现中单链表、循环链表和双向链表的创建、查找、插入和删除等基本操作及相关算法。ie下这些css3效果实现是借助于vml,由vml绘制圆角或是投影效果的容器元素,然后这个容器元素作为目标元素的后兄弟节点插入,如果目标元素position:absolute 或是 position:relative,则这个css3-container元素将会设置与之一样的z-index值,在dom tree中,同级的元素总是后面的覆盖前面的,所以这样就实现了覆盖,又避免了可能有其他元素正好插入其中。

下面是实现的主要代码:

function CirLinkList() {
function Node(element) {
this.element = element;
this.next = null;
}
var length = 0;
var head = null, tail = null;
this.append = function(element) {
var node = new Node(element), current;
if (!head) {
head = node;
head.next = head;
tail = head;
} else {
current = head;
while (current.next !== head) {
current = current.next;
}
current.next = node;
tail = node;
node.next = head;
}
length++;
return true;
}
this.insert = function(position,element) {
var node = new Node(element), current;
if (position > -1 && position < length) {
var index = 0,
current = head;
if (position === 0) {
node.next = head;
tail.next = node;
head = node;
} else {
while (index++ < position) {
current = current.next;
}
node.next = current.next;
current.next = node;
}
length++;
return true
} else {
return false;
}
}
this.remove = function(element) {
if (element === head.element) {
if (length === 1) {
head = null;
} else {
tail.next = head.next;
head = tail.next;
}
length--;
return true;
} else {
current = head;
while (current.next !== head) {
if (current.next.element === element) {
current.next = current.next.next;
if (current.next === head) tail = current;
length--;
return true;
}
current = current.next;
}
}
return false;
}
this.getHead = function() {
return head;
}
this.size = function() {
return length;
}
this.isEmpty = function() {
return head ? false : true;
}
}
let cirLink = new CirLinkList();
let i = 1;
cirLink.append(1);
cirLink.append(2);
cirLink.insert(0, 3);
cirLink.remove(3);
cirLink.insert(0, 0);
cirLink.append(3)
let current = cirLink.getHead();
while (current) {
console.log(current.element);
if (i === 6) break;
i++;
current = current.next;
}
复制代码

遍历结果0, 1, 2, 3, 0, 1
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-100969-1.html
放久了生蛆多正常
有种就什么方便面都不要吃
侦查得好啊
或者军事表演秀