Algoritma & Pemrograman (Stack Linier 2)
-
Upload
achmad-solichin -
Category
Documents
-
view
500 -
download
6
description
Transcript of Algoritma & Pemrograman (Stack Linier 2)
![Page 1: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/1.jpg)
STACK LINIERSTACK LINIERContoh Program dan PenjelasannyaContoh Program dan Penjelasannya
Oleh Achmad SolichinOleh Achmad SolichinAssisten Laboratorium Komputer FTI Assisten Laboratorium Komputer FTI
Universitas Budi LuhurUniversitas Budi Luhur08 April 200408 April 2004
![Page 2: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/2.jpg)
Niscaya Allah akan meninggikan derajat Niscaya Allah akan meninggikan derajat orang-orang yang beriman di antara orang-orang yang beriman di antara
kamu dan orang-orang kamu dan orang-orang
yang diberi ilmu pengetahuan yang diberi ilmu pengetahuan
beberapa derajat beberapa derajat
Dan Allah Maha Mengetahui apa yang Dan Allah Maha Mengetahui apa yang kamu kerjakan.kamu kerjakan.
(QS Al-Mujaadalah : 11) (QS Al-Mujaadalah : 11)
![Page 3: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/3.jpg)
#include "stdio.h"#include "stdio.h"
#include "conio.h"#include "conio.h"
#include "stdlib.h"#include "stdlib.h"
#include "ctype.h"#include "ctype.h"
void push();void push();
void pop();void pop();
void tampil();void tampil();
void reset();void reset();
int x[5],dasar=0;int x[5],dasar=0;
int atas=0,pil,bil;int atas=0,pil,bil;
HEADER FUNGSI
![Page 4: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/4.jpg)
#include "stdio.h"#include "stdio.h"
#include "conio.h"#include "conio.h"
#include "stdlib.h"#include "stdlib.h"
#include "ctype.h"#include "ctype.h"
void push();void push();
void pop();void pop();
void tampil();void tampil();
void reset();void reset();
int x[5],dasar=0;int x[5],dasar=0;
int atas=0,pil,bil;int atas=0,pil,bil;
DEKLARASI FUNGSI push();
![Page 5: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/5.jpg)
DEKLARASI FUNGSI pop();
#include "stdio.h"#include "stdio.h"
#include "conio.h"#include "conio.h"
#include "stdlib.h"#include "stdlib.h"
#include "ctype.h"#include "ctype.h"
void push();void push();
void pop();void pop();
void tampil();void tampil();
void reset();void reset();
int x[5],dasar=0;int x[5],dasar=0;
int atas=0,pil,bil;int atas=0,pil,bil;
![Page 6: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/6.jpg)
DEKLARASI FUNGSI tampil();
#include "stdio.h"#include "stdio.h"
#include "conio.h"#include "conio.h"
#include "stdlib.h"#include "stdlib.h"
#include "ctype.h"#include "ctype.h"
void push();void push();
void pop();void pop();
void tampil();void tampil();
void reset();void reset();
int x[5],dasar=0;int x[5],dasar=0;
int atas=0,pil,bil;int atas=0,pil,bil;
![Page 7: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/7.jpg)
DEKLARASI FUNGSI reset();
#include "stdio.h"#include "stdio.h"
#include "conio.h"#include "conio.h"
#include "stdlib.h"#include "stdlib.h"
#include "ctype.h"#include "ctype.h"
void push();void push();
void pop();void pop();
void tampil();void tampil();
void reset();void reset();
int x[5],dasar=0;int x[5],dasar=0;
int atas=0,pil,bil;int atas=0,pil,bil;
![Page 8: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/8.jpg)
DEKLARASI stack x[5], variabel dasar, atas, pil
dan bil
#include "stdio.h"#include "stdio.h"
#include "conio.h"#include "conio.h"
#include "stdlib.h"#include "stdlib.h"
#include "ctype.h"#include "ctype.h"
void push();void push();
void pop();void pop();
void tampil();void tampil();
void reset();void reset();
int x[5],dasar=0;int x[5],dasar=0;
int atas=0,pil,bil;int atas=0,pil,bil;
![Page 9: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/9.jpg)
void main()void main()
{{
menu :menu :
clrscr();clrscr();
gotoxy(25,3); gotoxy(25,3); printf("====================");printf("====================");
gotoxy(25,4); gotoxy(25,4);
printf(“ Menu pilihan : printf(“ Menu pilihan : "); ");
gotoxy(25,5); gotoxy(25,5); printf("====================");printf("====================");
gotoxy(25,6); printf(" 1. Push ");gotoxy(25,6); printf(" 1. Push ");
gotoxy(25,7); printf(" 2. Pop ");gotoxy(25,7); printf(" 2. Pop ");
![Page 10: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/10.jpg)
void main()void main()
{{
menu :menu :
clrscr();clrscr();
gotoxy(25,3); gotoxy(25,3); printf("====================");printf("====================");
gotoxy(25,4); gotoxy(25,4);
printf(“ Menu pilihan : printf(“ Menu pilihan : "); ");
gotoxy(25,5); gotoxy(25,5); printf("====================");printf("====================");
gotoxy(25,6); printf(" 1. Push ");gotoxy(25,6); printf(" 1. Push ");
gotoxy(25,7); printf(" 2. Pop ");gotoxy(25,7); printf(" 2. Pop ");
FUNGSI main();
![Page 11: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/11.jpg)
DEKLARASI LABEL
void main()void main()
{{
menu :menu :
clrscr();clrscr();
gotoxy(25,3); gotoxy(25,3); printf("====================");printf("====================");
gotoxy(25,4); gotoxy(25,4);
printf(“ Menu pilihan : printf(“ Menu pilihan : "); ");
gotoxy(25,5); gotoxy(25,5); printf("====================");printf("====================");
gotoxy(25,6); printf(" 1. Push ");gotoxy(25,6); printf(" 1. Push ");
gotoxy(25,7); printf(" 2. Pop ");gotoxy(25,7); printf(" 2. Pop ");
![Page 12: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/12.jpg)
MEMBERSIHKAN LAYAR
void main()void main()
{{
menu :menu :
clrscr();clrscr();
gotoxy(25,3); gotoxy(25,3); printf("====================");printf("====================");
gotoxy(25,4); gotoxy(25,4);
printf(“ Menu pilihan : printf(“ Menu pilihan : "); ");
gotoxy(25,5); gotoxy(25,5); printf("====================");printf("====================");
gotoxy(25,6); printf(" 1. Push ");gotoxy(25,6); printf(" 1. Push ");
gotoxy(25,7); printf(" 2. Pop ");gotoxy(25,7); printf(" 2. Pop ");
![Page 13: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/13.jpg)
MEMINDAHKAN CURSOR KE BARIS 25 , KOLOM 3
void main()void main()
{{
menu :menu :
clrscr();clrscr();
gotoxy(25,3); gotoxy(25,3); printf("====================");printf("====================");
gotoxy(25,4); gotoxy(25,4);
printf(“ Menu pilihan : printf(“ Menu pilihan : "); ");
gotoxy(25,5); gotoxy(25,5); printf("====================");printf("====================");
gotoxy(25,6); printf(" 1. Push ");gotoxy(25,6); printf(" 1. Push ");
gotoxy(25,7); printf(" 2. Pop ");gotoxy(25,7); printf(" 2. Pop ");
3
25
![Page 14: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/14.jpg)
gotoxy(25,8); gotoxy(25,8);
printf("3. Preview ");printf("3. Preview ");
gotoxy(25,9); gotoxy(25,9);
printf("4. Clear ");printf("4. Clear ");
gotoxy(25,10); gotoxy(25,10);
printf("5. Exit ");printf("5. Exit ");
gotoxy(25,11); gotoxy(25,11); printf("===========printf("===============");====");
gotoxy(25,12); gotoxy(25,12);
printf("Masukkan pilihan : printf("Masukkan pilihan : "); scanf("%i", &pil);"); scanf("%i", &pil);
![Page 15: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/15.jpg)
gotoxy(25,8); gotoxy(25,8);
printf("3. Preview ");printf("3. Preview ");
gotoxy(25,9); gotoxy(25,9);
printf("4. Clear ");printf("4. Clear ");
gotoxy(25,10); gotoxy(25,10);
printf("5. Exit ");printf("5. Exit ");
gotoxy(25,11); gotoxy(25,11); printf("===========printf("===============");====");
gotoxy(25,12); gotoxy(25,12);
printf("Masukkan pilihan : printf("Masukkan pilihan : "); scanf("%i", &pil);"); scanf("%i", &pil);
SAMPAI DI SINI PROGRAM AKAN MENAMPILKAN MENU PILIHAN BERUPA :1. Push2. Pop3. Preview4. Clear5. Exit
![Page 16: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/16.jpg)
gotoxy(25,8); gotoxy(25,8);
printf("3. Preview ");printf("3. Preview ");
gotoxy(25,9); gotoxy(25,9);
printf("4. Clear ");printf("4. Clear ");
gotoxy(25,10); gotoxy(25,10);
printf("5. Exit ");printf("5. Exit ");
gotoxy(25,11); gotoxy(25,11); printf("===========printf("===============");====");
gotoxy(25,12); gotoxy(25,12);
printf("Masukkan pilihan : printf("Masukkan pilihan : "); scanf("%i", &pil);"); scanf("%i", &pil);
Masukkan Pilihan
![Page 17: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/17.jpg)
gotoxy(25,8); gotoxy(25,8);
printf("3. Preview ");printf("3. Preview ");
gotoxy(25,9); gotoxy(25,9);
printf("4. Clear ");printf("4. Clear ");
gotoxy(25,10); gotoxy(25,10);
printf("5. Exit ");printf("5. Exit ");
gotoxy(25,11); gotoxy(25,11); printf("===========printf("===============");====");
gotoxy(25,12); gotoxy(25,12);
printf("Masukkan pilihan : printf("Masukkan pilihan : "); scanf("%i", &pil);"); scanf("%i", &pil);
MEMINTA INPUTAN BILANGAN INTEGER DAN DIMASUKKAN DALAM VARIABEL pil
![Page 18: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/18.jpg)
switch(pil)switch(pil) { case 1 : gotoxy(25,13); { case 1 : gotoxy(25,13);
printf("Masukkan bil = "); printf("Masukkan bil = "); scanf("%i", &bil);scanf("%i", &bil); push();push(); getch();getch(); break;break;
case 2 : pop(); break;case 2 : pop(); break; case 3 : tampil(); getch(); break;case 3 : tampil(); getch(); break; case 4 : reset(); getch(); break;case 4 : reset(); getch(); break; case 5 : exit(0); break;case 5 : exit(0); break; }} goto menu;goto menu;}}
![Page 19: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/19.jpg)
switch(pil)switch(pil) { case 1 : gotoxy(25,13); { case 1 : gotoxy(25,13);
printf("Masukkan bil = "); printf("Masukkan bil = "); scanf("%i", &bil);scanf("%i", &bil); push();push(); getch();getch(); break;break;
case 2 : pop(); break;case 2 : pop(); break; case 3 : tampil(); getch(); break;case 3 : tampil(); getch(); break; case 4 : reset(); getch(); break;case 4 : reset(); getch(); break; case 5 : exit(0); break;case 5 : exit(0); break; }} goto menu;goto menu;}}
STRUKTUR switch … case AKAN MEMERIKSA ISI VARIABEL pil YANG AKAN MENENTUKAN PERINTAH MANA YANGDILAKSANAKAN
Bentuk umum :switch(pilihan) { case 1 : <statemen>;
break; case 2 : <statemen>;
break; …… default : <statemen>;}
![Page 20: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/20.jpg)
switch(pil)switch(pil) { case 1 : gotoxy(25,13); { case 1 : gotoxy(25,13);
printf("Masukkan bil = "); printf("Masukkan bil = "); scanf("%i", &bil);scanf("%i", &bil); push();push(); getch();getch(); break;break;
case 2 : pop(); break;case 2 : pop(); break; case 3 : tampil(); getch(); break;case 3 : tampil(); getch(); break; case 4 : reset(); getch(); break;case 4 : reset(); getch(); break; case 5 : exit(0); break;case 5 : exit(0); break; }} goto menu;goto menu;}}
JIKA ISI VARIABEL pil=1MAKA STATEMENTDALAM BLOK INI AKANDILAKSANAKAN
![Page 21: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/21.jpg)
switch(pil)switch(pil) { case 1 : gotoxy(25,13); { case 1 : gotoxy(25,13);
printf("Masukkan bil = "); printf("Masukkan bil = "); scanf("%i", &bil);scanf("%i", &bil); push();push(); getch();getch(); break;break;
case 2 : pop(); break;case 2 : pop(); break; case 3 : tampil(); getch(); break;case 3 : tampil(); getch(); break; case 4 : reset(); getch(); break;case 4 : reset(); getch(); break; case 5 : exit(0); break;case 5 : exit(0); break; }} goto menu;goto menu;}}
MASUKKAN BILANGANYANG AKAN MASUKKE STACK
![Page 22: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/22.jpg)
switch(pil)switch(pil) { case 1 : gotoxy(25,13); { case 1 : gotoxy(25,13);
printf("Masukkan bil = "); printf("Masukkan bil = "); scanf("%i", &bil);scanf("%i", &bil); push();push(); getch();getch(); break;break;
case 2 : pop(); break;case 2 : pop(); break; case 3 : tampil(); getch(); break;case 3 : tampil(); getch(); break; case 4 : reset(); getch(); break;case 4 : reset(); getch(); break; case 5 : exit(0); break;case 5 : exit(0); break; }} goto menu;goto menu;}}
MEMINTA INPUTAN BILANGAN INTEGER DAN DIMASUKKAN DALAM VARIABEL bil
![Page 23: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/23.jpg)
switch(pil)switch(pil) { case 1 : gotoxy(25,13); { case 1 : gotoxy(25,13);
printf("Masukkan bil = "); printf("Masukkan bil = "); scanf("%i", &bil);scanf("%i", &bil); push();push(); getch();getch(); break;break;
case 2 : pop(); break;case 2 : pop(); break; case 3 : tampil(); getch(); break;case 3 : tampil(); getch(); break; case 4 : reset(); getch(); break;case 4 : reset(); getch(); break; case 5 : exit(0); break;case 5 : exit(0); break; }} goto menu;goto menu;}}
PANGGIL FUNGSI push() YANG MENGINPUTISI VARIABEL BIL KEDALAM STACK X
![Page 24: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/24.jpg)
switch(pil)switch(pil) { case 1 : gotoxy(25,13); { case 1 : gotoxy(25,13);
printf("Masukkan bil = "); printf("Masukkan bil = "); scanf("%i", &bil);scanf("%i", &bil); push();push(); getch();getch(); break;break;
case 2 : pop(); break;case 2 : pop(); break; case 3 : tampil(); getch(); break;case 3 : tampil(); getch(); break; case 4 : reset(); getch(); break;case 4 : reset(); getch(); break; case 5 : exit(0); break;case 5 : exit(0); break; }} goto menu;goto menu;}}
break; AKAN KELUAR DARI switch SEHINGGAPERINTAH YANG ADADI BAWAHNYA TIDAKAKAN DILAKSANAKAN
![Page 25: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/25.jpg)
switch(pil)switch(pil) { case 1 : gotoxy(25,13); { case 1 : gotoxy(25,13);
printf("Masukkan bil = "); printf("Masukkan bil = "); scanf("%i", &bil);scanf("%i", &bil); push();push(); getch();getch(); break;break;
case 2 : pop(); break;case 2 : pop(); break; case 3 : tampil(); getch(); break;case 3 : tampil(); getch(); break; case 4 : reset(); getch(); break;case 4 : reset(); getch(); break; case 5 : exit(0); break;case 5 : exit(0); break; }} goto menu;goto menu;}}
JIKA NILAI VARIABEL pil=2 MAKA PANGGIL FUNGSI pop() UNTUK MENGELUARKANISI STACK
![Page 26: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/26.jpg)
switch(pil)switch(pil) { case 1 : gotoxy(25,13); { case 1 : gotoxy(25,13);
printf("Masukkan bil = "); printf("Masukkan bil = "); scanf("%i", &bil);scanf("%i", &bil); push();push(); getch();getch(); break;break;
case 2 : pop(); break;case 2 : pop(); break; case 3 : tampil(); getch(); break;case 3 : tampil(); getch(); break; case 4 : reset(); getch(); break;case 4 : reset(); getch(); break; case 5 : exit(0); break;case 5 : exit(0); break; }} goto menu;goto menu;}}
JIKA NILAI VARIABEL pil=3 MAKA PANGGIL FUNGSI tampil() UNTUK MENAMPILKANISI STACK
![Page 27: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/27.jpg)
switch(pil)switch(pil) { case 1 : gotoxy(25,13); { case 1 : gotoxy(25,13);
printf("Masukkan bil = "); printf("Masukkan bil = "); scanf("%i", &bil);scanf("%i", &bil); push();push(); getch();getch(); break;break;
case 2 : pop(); break;case 2 : pop(); break; case 3 : tampil(); getch(); break;case 3 : tampil(); getch(); break; case 4 : reset(); getch(); break;case 4 : reset(); getch(); break; case 5 : exit(0); break;case 5 : exit(0); break; }} goto menu;goto menu;}}
JIKA NILAI VARIABEL pil=4 MAKA PANGGIL FUNGSI reset() UNTUK MENGEMBALIKAN ISIVARIABEL atas dan dasar
![Page 28: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/28.jpg)
switch(pil)switch(pil) { case 1 : gotoxy(25,13); { case 1 : gotoxy(25,13);
printf("Masukkan bil = "); printf("Masukkan bil = "); scanf("%i", &bil);scanf("%i", &bil); push();push(); getch();getch(); break;break;
case 2 : pop(); break;case 2 : pop(); break; case 3 : tampil(); getch(); break;case 3 : tampil(); getch(); break; case 4 : reset(); getch(); break;case 4 : reset(); getch(); break; case 5 : exit(0); break;case 5 : exit(0); break; }} goto menu;goto menu;}}
JIKA NILAI VARIABEL pil=5 MAKA PANGGIL FUNGSI exit(0) DIMANAPROGRAM AKAN SELESAI
![Page 29: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/29.jpg)
switch(pil)switch(pil) { case 1 : gotoxy(25,13); { case 1 : gotoxy(25,13);
printf("Masukkan bil = "); printf("Masukkan bil = "); scanf("%i", &bil);scanf("%i", &bil); push();push(); getch();getch(); break;break;
case 2 : pop(); break;case 2 : pop(); break; case 3 : tampil(); getch(); break;case 3 : tampil(); getch(); break; case 4 : reset(); getch(); break;case 4 : reset(); getch(); break; case 5 : exit(0); break;case 5 : exit(0); break; }} goto menu;goto menu;}}
MENUJU KE LABEL menu
![Page 30: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/30.jpg)
switch(pil)switch(pil) { case 1 : gotoxy(25,13); { case 1 : gotoxy(25,13);
printf("Masukkan bil = "); printf("Masukkan bil = "); scanf("%i", &bil);scanf("%i", &bil); push();push(); getch();getch(); break;break;
case 2 : pop(); break;case 2 : pop(); break; case 3 : tampil(); getch(); break;case 3 : tampil(); getch(); break; case 4 : reset(); getch(); break;case 4 : reset(); getch(); break; case 5 : exit(0); break;case 5 : exit(0); break; }} goto menu;goto menu;}}
AKHIR FUNGSI main()
![Page 31: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/31.jpg)
void push()void push()
{ if(atas<5){ if(atas<5)
{ x[atas] = bil;{ x[atas] = bil;
atas++;atas++;
gotoxy(25,14); gotoxy(25,14);
printf("%i telah masuk",bil);printf("%i telah masuk",bil);
tampil();tampil();
} else {} else {
gotoxy(25,14);gotoxy(25,14);
printf("Stack penuh"); printf("Stack penuh");
}}
}}
atas<5
x[atas]=bil
atas++
penuh
berhasil
FLOWCHART PUSH()
![Page 32: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/32.jpg)
void push()void push()
{ if(atas<5){ if(atas<5)
{ x[atas] = bil;{ x[atas] = bil;
atas++;atas++;
gotoxy(25,14); gotoxy(25,14);
printf("%i telah masuk",bil);printf("%i telah masuk",bil);
tampil();tampil();
} else {} else {
gotoxy(25,14);gotoxy(25,14);
printf("Stack penuh"); printf("Stack penuh");
}}
}}
FUNGSI push() YANGAKAN MENAMBAHKANBILANGAN YANG DIINPUT KE DALAMSTACK
![Page 33: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/33.jpg)
void push()void push()
{ if(atas<5){ if(atas<5)
{ x[atas] = bil;{ x[atas] = bil;
atas++;atas++;
gotoxy(25,14); gotoxy(25,14);
printf("%i telah masuk",bil);printf("%i telah masuk",bil);
tampil();tampil();
} else {} else {
gotoxy(25,14);gotoxy(25,14);
printf("Stack penuh"); printf("Stack penuh");
}}
}}
DALAM PROSES push()PERTAMA KALI DIPE-RIKSA APAKAH STACK SUDAH PENUH. JIKA atas MASIH KURANG DARI 5 (JUMLAH MAXSTACK) MAKA STACK MASIH BISA DIISI
![Page 34: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/34.jpg)
void push()void push()
{ if(atas<5){ if(atas<5)
{ x[atas] = bil;{ x[atas] = bil;
atas++;atas++;
gotoxy(25,14); gotoxy(25,14);
printf("%i telah masuk",bil);printf("%i telah masuk",bil);
tampil();tampil();
} else {} else {
gotoxy(25,14);gotoxy(25,14);
printf("Stack penuh"); printf("Stack penuh");
}}
}}
ISI VARIABEL bilDISALINKE STACK x INDEXYANG KE-atas
![Page 35: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/35.jpg)
void push()void push()
{ if(atas<5){ if(atas<5)
{ x[atas] = bil;{ x[atas] = bil;
atas++;atas++;
gotoxy(25,14); gotoxy(25,14);
printf("%i telah masuk",bil);printf("%i telah masuk",bil);
tampil();tampil();
} else {} else {
gotoxy(25,14);gotoxy(25,14);
printf("Stack penuh"); printf("Stack penuh");
}}
}}
POINTER atas DIGESER KE KANAN. atas = atas+1
![Page 36: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/36.jpg)
void push()void push()
{ if(atas<5){ if(atas<5)
{ x[atas] = bil;{ x[atas] = bil;
atas++;atas++;
gotoxy(25,14); gotoxy(25,14);
printf("%i telah masuk",bil);printf("%i telah masuk",bil);
tampil();tampil();
} else {} else {
gotoxy(25,14);gotoxy(25,14);
printf("Stack penuh"); printf("Stack penuh");
}}
}}
NYATAKAN BAHWAISI VARIABLE bilTELAH MASUK KESTACK
![Page 37: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/37.jpg)
void push()void push()
{ if(atas<5){ if(atas<5)
{ x[atas] = bil;{ x[atas] = bil;
atas++;atas++;
gotoxy(25,14); gotoxy(25,14);
printf("%i telah masuk",bil);printf("%i telah masuk",bil);
tampil();tampil();
} else {} else {
gotoxy(25,14);gotoxy(25,14);
printf("Stack penuh"); printf("Stack penuh");
}}
}}
PANGGIL FUNGSI tampil() UNTUK ME-NAMPILKAN ISI STACK
![Page 38: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/38.jpg)
void push()void push()
{ if(atas<5){ if(atas<5)
{ x[atas] = bil;{ x[atas] = bil;
atas++;atas++;
gotoxy(25,14); gotoxy(25,14);
printf("%i telah masuk",bil);printf("%i telah masuk",bil);
tampil();tampil();
} else {} else {
gotoxy(25,14);gotoxy(25,14);
printf("Stack penuh"); printf("Stack penuh");
}}
}}
NYATAKAN STACK PENUH JIKA KONDISI ATAS<5 TIDAK TERPENUHI
![Page 39: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/39.jpg)
void pop()void pop()
{ if(atas>0){ if(atas>0)
{ atas --;{ atas --;
bil = x[atas];bil = x[atas];
gotoxy(25,13); gotoxy(25,13);
printf("%i telah dihapus",bil);printf("%i telah dihapus",bil);
} else {} else {
gotoxy(25,13); gotoxy(25,13);
printf("Stack kosong");printf("Stack kosong");
}}
getch();getch();
}}
atas>5
atas --
bil=x[atas]
kosong
terhapus
FLOWCHART POP()
![Page 40: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/40.jpg)
void pop()void pop()
{ if(atas>0){ if(atas>0)
{ atas --;{ atas --;
bil = x[atas];bil = x[atas];
gotoxy(25,13); gotoxy(25,13);
printf("%i telah dihapus",bil);printf("%i telah dihapus",bil);
} else {} else {
gotoxy(25,13); gotoxy(25,13);
printf("Stack kosong");printf("Stack kosong");
}}
getch();getch();
}}
FUNGSI pop() YANGAKAN MENGELUARKANBILANGAN DALAMSTACK SATU PER SATU
![Page 41: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/41.jpg)
void pop()void pop()
{ if(atas>0){ if(atas>0)
{ atas --;{ atas --;
bil = x[atas];bil = x[atas];
gotoxy(25,13); gotoxy(25,13);
printf("%i telah dihapus",bil);printf("%i telah dihapus",bil);
} else {} else {
gotoxy(25,13); gotoxy(25,13);
printf("Stack kosong");printf("Stack kosong");
}}
getch();getch();
}}
DALAM PROSES pop()PERTAMA KALI DIPE-RIKSA APAKAH STACK KOSONG. JIKA atas MASIH LEBIH BESARDARI 0 (NILAI AWAL atas) MAKA STACK MASIH ADA ISINYA
![Page 42: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/42.jpg)
void pop()void pop()
{ if(atas>0){ if(atas>0)
{ atas --;{ atas --;
bil = x[atas];bil = x[atas];
gotoxy(25,13); gotoxy(25,13);
printf("%i telah dihapus",bil);printf("%i telah dihapus",bil);
} else {} else {
gotoxy(25,13); gotoxy(25,13);
printf("Stack kosong");printf("Stack kosong");
}}
getch();getch();
}}
POINTER atas DIGESER KE KIRI. atas = atas-1
![Page 43: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/43.jpg)
void pop()void pop()
{ if(atas>0){ if(atas>0)
{ atas --;{ atas --;
bil = x[atas];bil = x[atas];
gotoxy(25,13); gotoxy(25,13);
printf("%i telah dihapus",bil);printf("%i telah dihapus",bil);
} else {} else {
gotoxy(25,13); gotoxy(25,13);
printf("Stack kosong");printf("Stack kosong");
}}
getch();getch();
}}
ISI VARIABEL x[atas]DISALINKE VARIABEL bil
![Page 44: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/44.jpg)
void pop()void pop()
{ if(atas>0){ if(atas>0)
{ atas --;{ atas --;
bil = x[atas];bil = x[atas];
gotoxy(25,13); gotoxy(25,13);
printf("%i telah dihapus",bil);printf("%i telah dihapus",bil);
} else {} else {
gotoxy(25,13); gotoxy(25,13);
printf("Stack kosong");printf("Stack kosong");
}}
getch();getch();
}}
NYATAKAN BAHWAISI VARIABLE bilTELAH DIHAPUS DARISTACK
![Page 45: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/45.jpg)
void pop()void pop()
{ if(atas>0){ if(atas>0)
{ atas --;{ atas --;
bil = x[atas];bil = x[atas];
gotoxy(25,13); gotoxy(25,13);
printf("%i telah dihapus",bil);printf("%i telah dihapus",bil);
} else {} else {
gotoxy(25,13); gotoxy(25,13);
printf("Stack kosong");printf("Stack kosong");
}}
getch();getch();
}}
NYATAKAN STACK KOSONG JIKA KONDISI atas>0 TIDAK TERPENUHI
![Page 46: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/46.jpg)
void tampil()void tampil()
{ int i,baris;{ int i,baris;
i = 0;baris=17;i = 0;baris=17;
gotoxy(25,15); gotoxy(25,15); printf("==================printf("==================");");
gotoxy(25,16); gotoxy(25,16);
printf("Isi stack : ");printf("Isi stack : ");
while(i<atas)while(i<atas)
{ gotoxy(25,baris);{ gotoxy(25,baris);
printf("x[%i] = %2i", i, x[i]);printf("x[%i] = %2i", i, x[i]);
i++; baris++;i++; baris++;
}}
gotoxy(25,baris); gotoxy(25,baris); printf("=================\printf("=================\n");n");
gotoxy(25,++baris); gotoxy(25,++baris);
printf("Press any key ....");printf("Press any key ....");
}}
int i=0;
i<atas
i++;
cetakisi
stack
FLOWCHART TAMPIL()
![Page 47: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/47.jpg)
void tampil()void tampil()
{ int i,baris;{ int i,baris;
i = 0;baris=17;i = 0;baris=17;
gotoxy(25,15); gotoxy(25,15); printf("==================printf("==================");");
gotoxy(25,16); gotoxy(25,16);
printf("Isi stack : ");printf("Isi stack : ");
while(i<atas)while(i<atas)
{ gotoxy(25,baris);{ gotoxy(25,baris);
printf("º x = %2i", x[i]);printf("º x = %2i", x[i]);
i++; baris++;i++; baris++;
}}
gotoxy(25,baris); gotoxy(25,baris); printf("=================\printf("=================\n");n");
gotoxy(25,++baris); gotoxy(25,++baris);
printf("Press any key ....");printf("Press any key ....");
}}
PERULANGAN UNTUKMENAMPILKAN ISISTACK. PERULANGANDIMULAI DARI i=0SELAMA i<atas
![Page 48: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/48.jpg)
void reset()void reset()
{{
atas = 0;atas = 0;
dasar = 0;dasar = 0;
printf("Stack telah printf("Stack telah dikosongkan.....");dikosongkan.....");
}}
FUNGSI reset() UNTUKMENGEMBALIKAN STACK KEKEADAAN SEMUA(AWAL)DIMANA atas=0 DAN dasar=0
![Page 49: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/49.jpg)
SELESAISELESAI
![Page 50: Algoritma & Pemrograman (Stack Linier 2)](https://reader033.fdokumen.com/reader033/viewer/2022061119/546a9452af79596c298b4775/html5/thumbnails/50.jpg)
Alhamdulillahi Robbil ‘AlamiinAlhamdulillahi Robbil ‘Alamiin