jam digital

WELCOME TO MY BLOG "VIRGO_BLOG'S

SELAMAT DATANG DI BLOG SAYA, SELAMAT MENGUNJUNGINYA DAN SELAMAT MEMBACA.

Kota KLATEN tercinta, KLATEN BERSINAR

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Tempat Perbelanjaan kota KLATEN " MATAHARI PLAZA

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Warung Apung Rowo Jombor, KLATEN

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Candi Prambanan

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Minggu, 31 Oktober 2010

PROGRAM STACK

#include <cstdlib>
#include <iostream>

using namespace std;
class Stack{
public:
Stack(){
jum = 5;
last = 0;
}

void push(int data){
if(jum > last){
a[last] = data;
last = last + 1;
}
}

int pop(){
if(last > 0){
int temp = a[last - 1];
a[last - 1] = 0;
last = last – 1;
return temp;
}
}

void print(){
for(int i = 0; i < last; i++){
cout << a[i] << ” “;
}
}
private:
int a[5];
int jum;
int last;
};

int main(int argc, char *argv[])
{
Stack x;
x.push(2);
x.push(4);
x.push(11);
x.push(5);
x.push(7);
x.push(9);
x.push(30);
x.print();
cout<<endl;

x.pop();
x.pop();
x.pop();
x.pop();
//x.pop();
//x.pop();
x.print();
cout<<endl;

system(“PAUSE”);
return EXIT_SUCCESS;
}

TUGAS S-DATA ANTRIAN QUEUE

#include <cstdlib>
#include <iostream.h>
#define maks 5
//using namespace std;

class Queue{
friend ostream& operator << (ostream&, const Queue&);
//friend istream& operator >> (istream&, Queue&);
public :
Queue();
int penuh(int);
int kosong(int);
void cetak();
void enqueue(char);
char dequeue();
private :
int banyak;
char A[maks];
};

ostream& operator << (ostream& out, const Queue& s)
{
cout <<”\nIsi Queue :”;

for (int i=0; i<s.banyak; i++)
out << s.A[i] << ” “;
cout<<endl;
}

Queue::Queue(){
banyak = 0;
for (int i=0; i<maks; i++)
A[i]=’0′;
}

int Queue::penuh(int s)
{return s==maks?1:0;}

int Queue::kosong(int s)
{return s==0?1:0;}

void Queue::cetak()
{cout <<”\nIsi dalam Queue sekarang   :”;
for (int i=0; i<banyak; i++)
cout <<A[i]<<” “;
}
void Queue::enqueue(char x)
{
cout <<”\nElemen :” <<x<<”  Masuk pada antrian”;
if (penuh(banyak)) cout <<”  queue penuh”;
else if(A[0]==’0′){
A[0]=x;
banyak++;
}
else{
for (int i=banyak; i>=0; i–)
A[i+1]=A[i];
A[0]=x;
banyak++;
}
}

char Queue::dequeue()
{
char temp=A[--banyak];
cout <<”\nDequeue elemen –>” <<temp;
A[banyak]=’0′;
return temp;
}

main()
{
Queue q;
for (char c=’a'; c<’d'; c++)
{
q.enqueue(c);
cout <<q;
}
char p=q.dequeue();
q.cetak();
cout <<”\n\nCetak menggunakan overloading:” <<q;
cout<<endl;

system(“PAUSE”);
return EXIT_SUCCESS;
}

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More