// 배열로 구현하는 스택
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 에서 내장함수 추가했는줄 알았습니다.^^
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7130 | 11년 전 | 2301 | ||
| 7129 | 11년 전 | 703 | ||
| 7128 |
senseme
|
11년 전 | 1283 | |
| 7127 | 11년 전 | 1159 | ||
| 7126 | 11년 전 | 808 | ||
| 7125 | 11년 전 | 2939 | ||
| 7124 | 11년 전 | 1417 | ||
| 7123 |
잘살아보자
|
11년 전 | 1274 | |
| 7122 |
잘살아보자
|
11년 전 | 675 | |
| 7121 |
잘살아보자
|
11년 전 | 3022 | |
| 7120 |
잘살아보자
|
11년 전 | 2902 | |
| 7119 |
잘살아보자
|
11년 전 | 721 | |
| 7118 |
잘살아보자
|
11년 전 | 3423 | |
| 7117 |
잘살아보자
|
11년 전 | 846 | |
| 7116 | 11년 전 | 735 | ||
| 7115 | 11년 전 | 1023 | ||
| 7114 | 11년 전 | 829 | ||
| 7113 | 11년 전 | 648 | ||
| 7112 | 11년 전 | 1069 | ||
| 7111 | 11년 전 | 1784 | ||
| 7110 | 11년 전 | 1027 | ||
| 7109 |
버섯먹은나
|
11년 전 | 790 | |
| 7108 | 11년 전 | 623 | ||
| 7107 | 11년 전 | 2399 | ||
| 7106 | 11년 전 | 1947 | ||
| 7105 | 11년 전 | 2476 | ||
| 7104 | 11년 전 | 1413 | ||
| 7103 |
|
11년 전 | 2695 | |
| 7102 | 11년 전 | 3112 | ||
| 7101 | 11년 전 | 4432 | ||
| 7100 | 11년 전 | 5780 | ||
| 7099 | 11년 전 | 2127 | ||
| 7098 | 11년 전 | 1710 | ||
| 7097 | 11년 전 | 1441 | ||
| 7096 | 11년 전 | 1117 | ||
| 7095 |
잘살아보자
|
11년 전 | 849 | |
| 7094 |
잘살아보자
|
11년 전 | 1043 | |
| 7093 |
잘살아보자
|
11년 전 | 920 | |
| 7092 |
잘살아보자
|
11년 전 | 1406 | |
| 7091 |
잘살아보자
|
11년 전 | 2202 | |
| 7090 |
잘살아보자
|
11년 전 | 877 | |
| 7089 | 11년 전 | 1051 | ||
| 7088 | 11년 전 | 1701 | ||
| 7087 | 11년 전 | 1395 | ||
| 7086 | 11년 전 | 1298 | ||
| 7085 |
|
11년 전 | 1219 | |
| 7084 | 11년 전 | 1140 | ||
| 7083 | 11년 전 | 3490 | ||
| 7082 | 11년 전 | 1133 | ||
| 7081 | 11년 전 | 1728 | ||
| 7080 | 11년 전 | 2006 | ||
| 7079 | 11년 전 | 1312 | ||
| 7078 | 11년 전 | 1291 | ||
| 7077 | 11년 전 | 1288 | ||
| 7076 | 11년 전 | 757 | ||
| 7075 | 11년 전 | 1149 | ||
| 7074 |
네이비칼라
|
11년 전 | 1494 | |
| 7073 | 11년 전 | 1463 | ||
| 7072 |
|
11년 전 | 826 | |
| 7071 | 11년 전 | 1187 | ||
| 7070 | 11년 전 | 927 | ||
| 7069 | 11년 전 | 1692 | ||
| 7068 | 11년 전 | 1336 | ||
| 7067 |
TPSint
|
11년 전 | 723 | |
| 7066 | 11년 전 | 2147 | ||
| 7065 | 11년 전 | 6634 | ||
| 7064 | 11년 전 | 1285 | ||
| 7063 | 11년 전 | 1129 | ||
| 7062 | 11년 전 | 1062 | ||
| 7061 | 11년 전 | 906 | ||
| 7060 | 11년 전 | 1460 | ||
| 7059 | 11년 전 | 855 | ||
| 7058 |
EngineMan
|
11년 전 | 3395 | |
| 7057 | 11년 전 | 1240 | ||
| 7056 | 11년 전 | 1631 | ||
| 7055 | 11년 전 | 1005 | ||
| 7054 | 11년 전 | 2645 | ||
| 7053 |
네이비칼라
|
11년 전 | 1276 | |
| 7052 | 11년 전 | 2573 | ||
| 7051 | 11년 전 | 1931 | ||
| 7050 | 11년 전 | 2446 | ||
| 7049 | 11년 전 | 1393 | ||
| 7048 | 11년 전 | 2523 | ||
| 7047 | 11년 전 | 1339 | ||
| 7046 | 11년 전 | 1025 | ||
| 7045 | 11년 전 | 1051 | ||
| 7044 | 11년 전 | 5430 | ||
| 7043 | 11년 전 | 1220 | ||
| 7042 | 11년 전 | 777 | ||
| 7041 |
열라뽕똬이
|
11년 전 | 751 | |
| 7040 | 11년 전 | 1105 | ||
| 7039 | 11년 전 | 1452 | ||
| 7038 | 11년 전 | 1867 | ||
| 7037 | 11년 전 | 2171 | ||
| 7036 | 11년 전 | 1081 | ||
| 7035 | 11년 전 | 1400 | ||
| 7034 | 11년 전 | 1341 | ||
| 7033 |
열라뽕똬이
|
11년 전 | 987 | |
| 7032 | 11년 전 | 748 | ||
| 7031 | 11년 전 | 2174 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기