Program Stack Kuadrat
Karena pada semester ini dosen saya Kak Desti mengajar kan dengan cara membagi suatu program menjadi tiga bagian, maka program stack ini dibagi menjadi tiga bagian penyimpanan yaitu, stack.h (berisi header) , stack.c(berisi proses), mstack.c(berisi proses yang ingin ditampilkan)
//**********************************************************************
//file stack.h
//**********************************************************************
#include
#define nil NULL
#define max 100
#define top(s) (s).top
#define infotop(s) (s).info[(s).top]
#define false 0
#define true 1
#define boolean unsigned char
typedef struct stack
{
int top;
int info[max];
};
void createempty(stack*s);
boolean isfull(stack s) ;
void push(stack *s, int x);
boolean isempty(stack s) ;
void pop(stack *s) ;
void output(stack s) ;
//**********************************************************************
//file stack.c
//**********************************************************************
#include "stack.h"
void createempty(stack *s)
{
top(*s)=nil;
}
boolean isfull(stack s)
{
return (top(s)==max);
}
void push(stack *s, int x)
{
if(isfull(*s))
{
cout<<"Stack Penuh"< }
else
{
top(*s)++;
infotop(*s)=x;
}
}
boolean isempty(stack s)
{
return (top(s)==nil);
}
void output(stack s)
{
while (top(s) != 0)
{
cout< top(s)--;
}
}
void kuadrat(stack s)
{
while (top(s) != 0)
{
int infotop;
infotop(s)= infotop(s)*infotop(s);
cout< top(s)--;
}
}
//**********************************************************************
//file mstack.c
//**********************************************************************
#include "stack.c"
void main()
{
stack s;
createempty(&s);
int banyak,x;
cout<<"Masukkan banyak data : ";
cin>>banyak;
for (int i=0; i {
cout<<"Masukkan Isi : ";
cin>>x;
push(&s,x);
}
cout<<"isi "< output(s);
cout<<"Kuadrat "< kuadrat(s);
}
//**********************************************************************
//file stack.h
//**********************************************************************
#include
#define nil NULL
#define max 100
#define top(s) (s).top
#define infotop(s) (s).info[(s).top]
#define false 0
#define true 1
#define boolean unsigned char
typedef struct stack
{
int top;
int info[max];
};
void createempty(stack*s);
boolean isfull(stack s) ;
void push(stack *s, int x);
boolean isempty(stack s) ;
void pop(stack *s) ;
void output(stack s) ;
//**********************************************************************
//file stack.c
//**********************************************************************
#include "stack.h"
void createempty(stack *s)
{
top(*s)=nil;
}
boolean isfull(stack s)
{
return (top(s)==max);
}
void push(stack *s, int x)
{
if(isfull(*s))
{
cout<<"Stack Penuh"<
else
{
top(*s)++;
infotop(*s)=x;
}
}
boolean isempty(stack s)
{
return (top(s)==nil);
}
void output(stack s)
{
while (top(s) != 0)
{
cout<
}
}
void kuadrat(stack s)
{
while (top(s) != 0)
{
int infotop;
infotop(s)= infotop(s)*infotop(s);
cout<
}
}
//**********************************************************************
//file mstack.c
//**********************************************************************
#include "stack.c"
void main()
{
stack s;
createempty(&s);
int banyak,x;
cout<<"Masukkan banyak data : ";
cin>>banyak;
for (int i=0; i
cout<<"Masukkan Isi : ";
cin>>x;
push(&s,x);
}
cout<<"isi "<
cout<<"Kuadrat "<
}
Tidak ada komentar:
Posting Komentar