// 배열로 구현하는 스택
3
2
1
Pop 3
Stack contents : Top ----> Bottom
2
1
Push 4, 5, 6
Stack contents : Top ----> Bottom
6
5
4
2
1
Now stack is full, push 7
Stack overflow.
Stack contents : Top ----> Bottom
6
5
4
2
1
Initialize stack
Stack contents : Top ----> Bottom
Now stack is empty
Pop
Stack underflow.
Push 7, 8
Stack contents : Top ----> Bottom
8
7
// 스택 최대크기 5
define('MAX', 5);
$top = 0;
$stack = array();
function init_stack() {
Global $top;
$top = -1;
}
function push($t) {
Global $top, $stack;
if ($top >= MAX - 1) {
println('Stack overflow.');
return -1;
}
$stack[++$top] = $t;
}
function pop() {
Global $top, $stack;
if ($top < 0) {
println('Stack underflow.');
return -1;
}
return $stack[$top--];
}
function print_stack() {
Global $top, $stack;
println('Stack contents : Top ----> Bottom');
for ($i = $top; $i >= 0; $i--)
println($stack[$i]);
}
init_stack();
println('Push 1, 2, 3');
push(1);
push(2);
push(3);
print_stack();
println();
$i = pop();
println("Pop ". $i);
print_stack();
println();
println('Push 4, 5, 6');
push(4);
push(5);
push(6);
print_stack();
println();
println('Now stack is full, push 7');
push(7);
print_stack();
println();
println('Initialize stack');
init_stack();
print_stack();
println();
println('Now stack is empty');
println('Pop');
pop();
println('Push 7, 8');
push(7);
push(8);
print_stack();
println();
function println($val='') {
echo $val.'<br />';
}
/* output
Push 1, 2, 3
Stack contents : Top ----> Bottom3
2
1
Pop 3
Stack contents : Top ----> Bottom
2
1
Push 4, 5, 6
Stack contents : Top ----> Bottom
6
5
4
2
1
Now stack is full, push 7
Stack overflow.
Stack contents : Top ----> Bottom
6
5
4
2
1
Initialize stack
Stack contents : Top ----> Bottom
Now stack is empty
Pop
Stack underflow.
Push 7, 8
Stack contents : Top ----> Bottom
8
7
*/
댓글 3개
11년 전
??? php에서 println 되나요? 이건 자바에서 출력및줄바꿈인데...
11년 전
println 은 사용자 함수입니다.
function println($val='') {
echo $val.'<br />';
}
function println($val='') {
echo $val.'<br />';
}
11년 전
아~ ^^
function 보지 못했습니다.^^
나는 또 println 함수가 php 에서 내장함수 추가했는줄 알았습니다.^^
function 보지 못했습니다.^^
나는 또 println 함수가 php 에서 내장함수 추가했는줄 알았습니다.^^
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6030 | 12년 전 | 2824 | ||
| 6029 | 12년 전 | 2850 | ||
| 6028 | 12년 전 | 1475 | ||
| 6027 | 12년 전 | 893 | ||
| 6026 |
kiplayer
|
12년 전 | 802 | |
| 6025 | 12년 전 | 589 | ||
| 6024 | 12년 전 | 2813 | ||
| 6023 | 12년 전 | 2953 | ||
| 6022 |
|
12년 전 | 2109 | |
| 6021 |
Holyreign
|
12년 전 | 1339 | |
| 6020 | 12년 전 | 786 | ||
| 6019 | 12년 전 | 2862 | ||
| 6018 | 12년 전 | 3192 | ||
| 6017 | 12년 전 | 1242 | ||
| 6016 |
kiplayer
|
12년 전 | 10575 | |
| 6015 |
itlang
|
12년 전 | 1420 | |
| 6014 | 12년 전 | 426 | ||
| 6013 |
senseme
|
12년 전 | 1364 | |
| 6012 | 12년 전 | 3115 | ||
| 6011 | 12년 전 | 7132 | ||
| 6010 | 12년 전 | 8965 | ||
| 6009 | 12년 전 | 2869 | ||
| 6008 | 12년 전 | 2992 | ||
| 6007 | 12년 전 | 6677 | ||
| 6006 | 12년 전 | 10515 | ||
| 6005 | 12년 전 | 4051 | ||
| 6004 |
|
12년 전 | 582 | |
| 6003 | 12년 전 | 887 | ||
| 6002 | 12년 전 | 2353 | ||
| 6001 | 12년 전 | 688 | ||
| 6000 |
kiplayer
|
12년 전 | 3742 | |
| 5999 | 12년 전 | 435 | ||
| 5998 |
|
12년 전 | 2941 | |
| 5997 |
|
12년 전 | 3441 | |
| 5996 | 12년 전 | 2095 | ||
| 5995 |
kiplayer
|
12년 전 | 2174 | |
| 5994 |
|
12년 전 | 3269 | |
| 5993 |
windowhan
|
12년 전 | 677 | |
| 5992 | 12년 전 | 2903 | ||
| 5991 | 12년 전 | 5234 | ||
| 5990 | 12년 전 | 1642 | ||
| 5989 |
AMDbest
|
12년 전 | 1352 | |
| 5988 | 12년 전 | 1220 | ||
| 5987 |
kiplayer
|
12년 전 | 1137 | |
| 5986 |
한번잘해보자
|
12년 전 | 928 | |
| 5985 |
kiplayer
|
12년 전 | 3141 | |
| 5984 |
dsv421
|
12년 전 | 807 | |
| 5983 |
dsv421
|
12년 전 | 1508 | |
| 5982 |
dsv421
|
12년 전 | 5837 | |
| 5981 | 12년 전 | 3214 | ||
| 5980 |
MFBob
|
12년 전 | 2623 | |
| 5979 | 12년 전 | 3099 | ||
| 5978 |
AMDbest
|
12년 전 | 1460 | |
| 5977 | 12년 전 | 793 | ||
| 5976 | 12년 전 | 1210 | ||
| 5975 | 12년 전 | 1274 | ||
| 5974 | 12년 전 | 612 | ||
| 5973 |
kiplayer
|
12년 전 | 3550 | |
| 5972 |
kiplayer
|
12년 전 | 3976 | |
| 5971 |
kiplayer
|
12년 전 | 2298 | |
| 5970 |
kiplayer
|
12년 전 | 8291 | |
| 5969 |
kiplayer
|
12년 전 | 949 | |
| 5968 | 12년 전 | 8741 | ||
| 5967 |
|
12년 전 | 16904 | |
| 5966 | 12년 전 | 1228 | ||
| 5965 | 12년 전 | 708 | ||
| 5964 | 12년 전 | 6247 | ||
| 5963 | 12년 전 | 705 | ||
| 5962 | 12년 전 | 885 | ||
| 5961 | 12년 전 | 636 | ||
| 5960 | 12년 전 | 786 | ||
| 5959 |
|
12년 전 | 1124 | |
| 5958 | 12년 전 | 978 | ||
| 5957 |
웹디자인되고파
|
12년 전 | 1088 | |
| 5956 | 12년 전 | 3657 | ||
| 5955 | 12년 전 | 2139 | ||
| 5954 | 12년 전 | 4396 | ||
| 5953 | 12년 전 | 3085 | ||
| 5952 | 12년 전 | 4267 | ||
| 5951 | 12년 전 | 2075 | ||
| 5950 | 12년 전 | 1277 | ||
| 5949 | 12년 전 | 930 | ||
| 5948 | 12년 전 | 2076 | ||
| 5947 | 12년 전 | 5000 | ||
| 5946 |
dsv421
|
12년 전 | 1274 | |
| 5945 |
dsv421
|
12년 전 | 4120 | |
| 5944 |
dsv421
|
12년 전 | 5645 | |
| 5943 | 12년 전 | 1283 | ||
| 5942 | 12년 전 | 2539 | ||
| 5941 |
프로프리랜서
|
12년 전 | 1644 | |
| 5940 |
atria
|
12년 전 | 614 | |
| 5939 | 12년 전 | 2339 | ||
| 5938 | 12년 전 | 2079 | ||
| 5937 |
프로프리랜서
|
12년 전 | 766 | |
| 5936 |
프로프리랜서
|
12년 전 | 713 | |
| 5935 |
프로프리랜서
|
12년 전 | 3211 | |
| 5934 |
프로프리랜서
|
12년 전 | 1629 | |
| 5933 |
AMDbest
|
12년 전 | 647 | |
| 5932 |
AMDbest
|
12년 전 | 502 | |
| 5931 | 12년 전 | 8141 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기