Skip to content

Commit 5782d5b

Browse files
committed
first commit Array Stack
0 parents  commit 5782d5b

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

Array/Array.html

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Array</title>
6+
</head>
7+
<body>
8+
<h3>数组方法总结</h3>
9+
<p>
10+
<h4>数组合并方法</h4>
11+
concat();
12+
</p>
13+
<p>
14+
<h4>搜索和排序</h4>
15+
indexOf();
16+
lastIndexOf();
17+
reverse();
18+
sort();
19+
</p>
20+
<p>
21+
<h4>栈方法</h4>
22+
push();
23+
pop();
24+
</p>
25+
<p>
26+
<h4>堆方法</h4>
27+
unshift();
28+
shift();
29+
</p>
30+
<p>
31+
<h4>删除方法</h4>
32+
slice();
33+
splice();
34+
</p>
35+
<p>
36+
<h4>迭代方法</h4>
37+
every();
38+
some();
39+
map();
40+
filter();
41+
forEach();
42+
</p>
43+
<p>
44+
<h4>归一方法</h4>
45+
reduce();
46+
rightReduce();
47+
</p>
48+
</body>
49+
</html>

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Data-Constructs-and-Algorithms

Stack/Stack.html

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Algorithms && Data Struct</title>
6+
<script type="text/javascript">
7+
//Stack
8+
function Stack(){
9+
var items = [];
10+
//进栈
11+
this.push = function(element){
12+
items.push(element);
13+
};
14+
//出栈
15+
this.pop = function(){
16+
return items.pop();
17+
};
18+
//返回栈顶元素
19+
this.peek = function(){
20+
return items[items.length - 1];
21+
};
22+
//栈判空,空返回true,反之返回false
23+
this.isEmpty = function(){
24+
return items.length == 0;
25+
};
26+
//清空栈
27+
this.clear = function(){
28+
items = [];//items.length = 0;
29+
};
30+
//返回栈中元素个数
31+
this.size = function(){
32+
return items.length;
33+
};
34+
//查看栈中元素
35+
this.print = function(){
36+
console.log(items.toString());
37+
};
38+
}
39+
//十进制转换为其他进制
40+
function divideByBase(decNumber,base){
41+
var remStack = new Stack();
42+
var rem;
43+
var binaryString = '';
44+
var digits = "0123456789ABCDEF";
45+
while(decNumber > 0){
46+
rem = Math.floor(decNumber % base);
47+
if(base != 16){
48+
remStack.push(rem);
49+
}else{
50+
remStack.push(digits[rem]);
51+
}
52+
decNumber = Math.floor(decNumber / base);
53+
}
54+
while(!remStack.isEmpty()){
55+
binaryString += remStack.pop().toString();
56+
}
57+
return binaryString;
58+
}
59+
console.log(divideByBase(126,8));
60+
</script>
61+
</head>
62+
<body>
63+
64+
</body>
65+
</html>

0 commit comments

Comments
 (0)