#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define MAX_STACK 10
struct tumpukan
{
int top;
char data[ 10 ] [ 10 ] ;
} ;
struct tumpukan tumpuk;
void inisialisasi( )
{
tumpuk.top = - 1 ;
}
void push( char d[ 10 ] )
{
tumpuk.top ++;
strcpy ( tumpuk.
data [ tumpuk.
top ] , d
) ; }
void pop( )
{
printf ( "Data yang diambil adalah : %s \n " , tumpuk.
data [ tumpuk.
top ] ) ; tumpuk.top --;
}
void tampilkan( i)
{
for ( i= tumpuk.top ; i>= 0 ; i-- )
{
printf ( "Stack ke -%i adalah : %s \n " , i
, tumpuk.
data [ i
] ) ; }
}
int isKosong( )
{
if ( tumpuk.top ==- 1 )
{
return 1 ;
}
else
return 0 ;
}
int isPenuh( )
{
if ( tumpuk.top == MAX_STACK- 1 )
return 1 ;
else
return 0 ;
}
void search( int i)
{
char tmp[ 10 ] ;
while ( i<= tumpuk.top )
{
strcpy ( tumpuk.
data [ i
] , tumpuk.
data [ i
+ 1 ] ) ;
i++;
}
pop( ) ;
}
main( )
{
int pil, bil;
inisialisasi( ) ;
char dt[ 10 ] ;
printf ( "Selamat datang di program Stack \n " ) ;
printf ( "5.Search And Remove \n " ) ;
do
{
switch ( pil)
{
case 1 : if ( isPenuh( ) != 1 )
{
push( dt) ;
}
else
{
}
break ;
case 2 : if ( isKosong( ) != 1 )
{
pop( ) ;
}
else
{
}
break ;
case 3 : if ( isKosong( ) != 1 )
{
tampilkan( ) ;
}
else
{
}
break ;
case 4 : if ( isKosong( ) != 1 )
{
printf ( "cari data yang akan dihilangkan : " ) ; scanf ( "%i" ,& bil
) ; search( bil) ;
}
else
{
}
break ;
}
} while ( pil!= 6 ) ;
return 0 ;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8Y29uaW8uaD4KI2luY2x1ZGU8c3RyaW5nLmg+CiNpbmNsdWRlPHN0ZGxpYi5oPgoKI2RlZmluZSBNQVhfU1RBQ0sgMTAKCnN0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dWsuZGF0YVtpKzFdLHRtcCk7CgogICAgICAgIGkrKzsKICAgIH0KCiAgICBwb3AoKTsKfQoKbWFpbigpCnsKICAgIGludCBwaWwsYmlsOwogICAgaW5pc2lhbGlzYXNpKCk7CiAgICBjaGFyIGR0WzEwXTsKCiAgICBwcmludGYoIlNlbGFtYXQgZGF0YW5nIGRpIHByb2dyYW0gU3RhY2sgXG4iKTsKCiAgICBwcmludGYoIjEuUHVzaCBcbiIpOwogICAgcHJpbnRmKCIyLlBvcCBcbiIpOwogICAgcHJpbnRmKCIzLlRhbXBpbGthbiBcbiIpOwogICAgcHJpbnRmKCI0LkNsZWFyIFxuIik7CiAgICBwcmludGYoIjUuU2VhcmNoIEFuZCBSZW1vdmUgXG4iKTsKICAgIHByaW50ZigiNi5FeGl0IFxuIik7CgoKICAgIGRvCiAgICB7CiAgICAgICAgcHJpbnRmKCJNYXN1a2thbiBQaWxpaGFuIDogICIpO3NjYW5mKCIlaSIsJnBpbCk7CiAgICAgICAgc3dpdGNoKHBpbCkKICAgICAgICB7CiAgICAgICAgICAgIGNhc2UgMSA6IGlmIChpc1BlbnVoKCkhPTEpCiAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgIHByaW50ZigiTWFzdWtrYW4gQ29udGVudCBTdGFjayA6ICIpO3NjYW5mKCIlcyIsJmR0KTsKICAgICAgICAgICAgICAgICAgICAgICAgIHB1c2goZHQpOwogICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcHJpbnRmKCJzdWRhaCBwZW51aCBcbiIpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDIgIDogaWYgKGlzS29zb25nKCkhPTEpCiAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcG9wKCk7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcHJpbnRmKCJNYXNpaCBLb3NvbmcgXG4iKTsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDMgIDogaWYgKGlzS29zb25nKCkhPTEpCiAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgdGFtcGlsa2FuKCk7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHByaW50ZigiTWFzaWgga29zb25nIFxuIik7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDQgIDogaWYgKGlzS29zb25nKCkhPTEpCiAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcHJpbnRmKCJjYXJpIGRhdGEgeWFuZyBha2FuIGRpaGlsYW5na2FuICAgOiAiKTtzY2FuZigiJWkiLCZiaWwpOwogICAgICAgICAgICAgICAgICAgICAgICAgIHNlYXJjaChiaWwpOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwcmludGYoIk1hc2loIEtvc29uZyBcbiIpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICB9d2hpbGUocGlsIT02KTsKCiAgICByZXR1cm4gMDsKfQ==
compilation info
prog.c:2:18: error: conio.h: No such file or directory
prog.c:76: warning: return type defaults to ‘int’
prog.c: In function ‘main’:
prog.c:98: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[10]’
prog.c:93: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
prog.c:98: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
prog.c:126: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
stdout