Selasa, 09 Februari 2010

SOAL 2
#include (iostream.h>
#include (string.h>
#include (dos.h>
#include (stdlib.h>
#include (conio.h>

class elemen
{
struct list
{
int bil;
struct list *next;
};

public:
typedef struct list NODE;
typedef NODE *PNODE;

void tampil_stack (PNODE atas);
void PUSH (PNODE *atas, PNODE baru);
void POP (PNODE *atas);
PNODE masuk_stack (void);

void tampil_queue (PNODE head);
void insert (PNODE *tail,PNODE *head, PNODE baru);
void INSERT_QUEUE (PNODE *tail,PNODE *head, PNODE baru);
void DELETE_QUEUE (PNODE *head, PNODE *tail);
PNODE masuk_queue (void);
};

void elemen :: tampil_stack (PNODE atas)
{
PNODE pos;
pos = atas;
cout<<"\n\nbilangan : "; while(pos != NULL) { cout< bil<<", "; pos = pos -> next;
}
cout<<"\n\n\n [TEKAN ENTER UNTUK MELANJUTKAN]"; getch(); } void elemen :: PUSH (PNODE *atas, PNODE baru) { if (*atas == NULL) { *atas = baru; } else{ baru -> next = *atas;
*atas = baru;
}
}

void elemen :: POP (PNODE *atas)
{
PNODE PH;
PH = *atas;

if(*atas == NULL)
{
cout<<"\n\nSTACK KOSONG !!!\n\n"; } else { if (PH -> next == NULL)
{
*atas = NULL;
free(PH);
}
else
{
*atas = (*atas) -> next;
free(PH);
}
}
getch();
}

PNODE elemen :: masuk_stack (void)
{
PNODE baru;
baru = (NODE *) malloc (sizeof(NODE));
cout<<"\nbil : ";cin>>baru->bil;
baru -> next = NULL;
return (baru);
getch();
}

void elemen :: tampil_queue (PNODE head)
{
PNODE pos;
pos = head;
cout<<"\n\nbilangan : "; while(pos != NULL) { cout< bil<<", "; pos = pos -> next;

}
cout<<"\n\n\n [TEKAN ENTER UNTUK MELANJUTKAN]"; getch(); } void elemen :: INSERT_QUEUE (PNODE *tail,PNODE *head, PNODE baru) { if(*tail == NULL) { *head = baru; *tail = baru; } else { (*tail) -> next = baru;
*tail = baru;
}
}

void elemen :: DELETE_QUEUE (PNODE *head, PNODE *tail)
{
PNODE PH;
PH = *head;
if(*head == NULL)
{
cout<<"\n\nQUEUE KOSONG !!!\n\n"; } else { if (PH -> next == NULL)
{
*head = NULL;
*tail = NULL;
free(PH);
}
else
{
*head = (*head) -> next;
free(PH);
}
}
getch();
}

PNODE elemen :: masuk_queue (void)
{
PNODE baru;
baru = (NODE *)malloc(sizeof(NODE));
cout<<"\nbil : ";cin>>baru -> bil;
baru -> next = NULL;
return(baru);
getch();
}


void main()
{
PNODE atas = NULL;
PNODE baru;
PNODE head = NULL,tail = NULL;
int pil=1, x, m;
char *a = "Created bY Tendi Setiadi (6306211) ";
char *b = "Í";
elemen data;
textbackground (RED);
clrscr();

m=strlen(a);
gotoxy (20,20);
for (x=0; x<<*(a+x); delay(200); } gotoxy (3,24); for (x=0; x<75; x++) { cout<<*b; delay(40); } while (pil != 3) { clrscr(); cout<<"\n-> Menu Utama <-"<<<"\n1> Stack";
cout<<"\n2> Queue";
cout<<"\n3> Exit";
cout<<"\nPilihan : ";cin>>pil;

if (pil == 1)
{
while(pil != 4)
{
clrscr();
cout<<"\n>> Menu STACK <<"<<<"\n1. PUSH STACK"; cout<<"\n2. LIHAT DATA STACK"; cout<<"\n3. POP STACK"; cout<<"\n4. Menu Utama"; cout<<"\nPilihan : ";cin>>pil;

if (pil == 1)
{
baru = data.masuk_stack();
data.PUSH(&atas, baru);
}

if (pil == 2)
data.tampil_stack(atas);

if (pil == 3)
{
data.POP(&atas);
}
}
}

if (pil == 2)
{
while(pil != 4)
{
clrscr();
cout<<"\n>> Menu QUEUE <<"<<<"\n1. INSERT_QUEUE LIST"; cout<<"\n2. LIHAT DATA LIST"; cout<<"\n3. DELETE_QUEUE LIST"; cout<<"\n4. Menu Utama"; cout<<"\nPilihan : ";cin>>pil;

if (pil == 1)
{
baru=data.masuk_queue();
data.INSERT_QUEUE(&tail,&head,baru);
}

if (pil == 2)
data.tampil_queue(head);

if (pil == 3)
{
data.DELETE_QUEUE(&head,&tail);
}
}
}
}
}






SOAL 3
#include "iostream.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"

struct list
{
char nama[35];
char kode[10];
struct list * next;
};
typedef struct list node;
typedef node * pnode;
typedef struct list NODE;
typedef NODE * PNODE;

void TAMPIL(PNODE ATAS)
{
int x;
PNODE POS;
POS = ATAS;
cout<<"\nKode : "; while(POS!=NULL) { cout<kode<<" - "; POS=POS->next;
}
}

void PUSH(PNODE *ATAS,PNODE BARU)
{
if(*ATAS==NULL)
{
*ATAS = BARU;
}
else
{
BARU->next = *ATAS;
*ATAS = BARU;
}
}

void POP(PNODE *ATAS)
{
PNODE PH;
PH = *ATAS;
if(*ATAS==NULL)
{
cout<<"\n\nSTACK KOSONG !!!\n\n"; } else { if (PH->next==NULL)
{
*ATAS = NULL;
free(PH);
}
Else
{
*ATAS = (*ATAS)->next;
free(PH);
}
}
}

PNODE MASUK(void)
{
PNODE BARU;
BARU=new(NODE);
cout<<"KODE : "; gets(BARU->kode);
BARU->next=NULL;
return(BARU);
}

void tampil(pnode atas)
{
int x;
pnode pos;
pos = atas;
cout<<"NEGARA : "; while(pos!=NULL) { cout<nama<<" - "; pos=pos->next;
}
}

void push(pnode *atas, pnode baru)
{
if(*atas==NULL)
{
*atas = baru;
}
else
{
baru->next = *atas;
*atas = baru;
}
}

void pop(pnode *atas)
{
pnode ph;
ph = *atas;

if(*atas==NULL)
{
cout<<"\n\nSTACK KOSONG !!!\n\n"; } else { if (ph->next==NULL)
{
*atas = NULL;
free(ph);
}
else
{
*atas = (*atas)->next;
free(ph);
}
}
}

pnode masuk(void)
{
pnode baru;
baru=new(node);
cout<<"\nNEGARA : "; gets(baru->nama);
baru->next=NULL;
return(baru);
}

void main()
{
pnode atas=NULL;
pnode baru;
PNODE BARU;
PNODE ATAS=NULL;
int pil=1;
clrscr();

while(pil!=4)
{
cout<<"\n\n=======STACK======="; cout<<"\n1. PUSH STACK"; cout<<"\n2. VIEW DATA STACK"; cout<<"\n3. POP STACK"; cout<<"\n4. EXIT"; cout<<"\nPilihan [1/2/3/4] : "; cin>>pil;

if (pil==1)
{
clrscr();
baru=masuk();
BARU=MASUK();
push(&atas,baru);
PUSH(&ATAS,BARU);
}
if (pil==2)
{
clrscr();
tampil(atas);
TAMPIL(ATAS);
}
if (pil==3)
{
clrscr();
pop(&atas);
POP(&ATAS);
}
}
}

Tidak ada komentar:

Posting Komentar