Program Membalikkan Kata dengan Single Stack pada C++

/*########################################*/
/* Membalikan kata dengan single stack */
/* by Ma’shum Rois */

# include
# include

#define MAX 75
#define true 1
#define false 0

char stack[MAX];
int top;

void init(void);
int full(void);

int empty(void);
char pop(void);
void clear(void);
void push(char info);

main()
{
char pilih;
char kal[75];
int k,p;

printf(“–Membalik Kata Dengan Stack–\n”);
init();

do
{
printf(“MENU PILIHAN :\n”);
printf(“[1] MASUKAN KATA\n”);
printf(“[2] BACA BALIKAN\n”);
printf(“[3] SELESAI\n”);
printf(” Pilihan : “);
scanf(“%s”, &pilih);
switch(pilih)
{
case’1′:printf(“Masukan Kata : “);
scanf(“%s”, &kal);
p=strlen(kal);
for(k=0;k<=p;k++)
push(kal[k]);
printf(“Kata yang masuk:”);
for(k=1;k=1;k–)
printf(“%c”,pop());
printf(“\n”);
}
else printf(“Stack kosong\n”);
break;
case’3′ : break;
default : printf(“Salah pilih…\n”);
}
printf(“\n”);
}while(pilih!=’3′);
}

void init(void)
{
top=0;
}

void push(char info)
{
if(full()!=true)
{
top++;
stack[top]=info;
}
else
printf(“Stack overflow…\n”);
}

char pop(void)
{
char info;
if(empty()!=true)
{
info=stack[top];
top–;
return(info);
}
else
printf(“Stack underflow…\n”);
}

int full(void)
{
if(top==MAX)
return(true);
else
return(false);
}
int empty(void)
{
if(top==0)
return(true);
else
return(false);
}

2 Komentar to “Program Membalikkan Kata dengan Single Stack pada C++”

  1. Furthermore, the Wireless Control Center lets you secure
    your program with a custom four-digit code that can be used or
    tritium which a non-electrical sign. Some estimate that the sparks can fly as far as 35 feet and others say that they
    can help to manage the risks.

    Suka

  2. Holiday about teacher training courses is ensured when an expert specifies what amperes should
    be used. The memos are included in the Washington County guide.
    A good way to help children respond correctly to fire
    emergencies. That basically covers whatever it is that you
    may realize at first glance. See if your kids can answer
    the top ten questions about about teacher training courses.

    Suka

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: