Juli 29, 2010

c++ program senarai berantai (stack/tumpukan)

Hmmmm pulang uas cape dan hasil waktu uas sebernya si program di jalankan error tapi yah saya tidak putus semangat dan mencoba lagi untuk memuasakan rasa penasaran saya gitu .. and well hasilnya rasa penasaran saya pun terbayar pula..
hah... daripada ngoceh ngak jelas mendingan langsung caw aja om..
source code nya monggo gan....


//single linklist stact atau senarai berantai tunggal tumpukan //

#include<constream.h>

#include<stdlib.h>

struct node{

int no;

struct node * next;

};

typedef node NODE;

typedef NODE * PNODE;

PNODE head=NULL;

PNODE tail=NULL;

int menu();

void tampil(PNODE );

void MskDtList(PNODE * );

PNODE IsiNode();

void main (void){

clrscr();

int pil = -1;

PNODE baru;

while (pil != 3){

pil = menu();

switch (pil){

case 1 : baru = IsiNode();

if (baru == NULL)

cout<<"data tidak terisi ";

else

MskDtList(&baru);

break;

case 2 : tampil(head); break;

default :



break;

}

}

}



int menu(){

int pil=-1;

cout<<" menu link list "<<endl;

cout<<" 1- isi data "<<endl;

cout<<" 2- tampil data "<<endl;

cout<<" 3- exit "<<endl;

while (pil< 1 || pil >3){

cout << "masuakan pilihan anda dari menu : "<<endl;

cin>>pil;

}

return (pil);

}



PNODE IsiNode(){

PNODE * p_top;

*p_top = (struct node *) malloc(sizeof(node));

cout <<" masukan bilangan : "<<endl;

cin>>(*p_top)->no;

(*p_top)->next = NULL;

return (*p_top);

}

void MskDtList(PNODE * p_top){

if(head == NULL){

head = (*p_top);

tail = (*p_top);

return;

}

(*p_top)->next = head;

head = (*p_top);

}

void tampil(PNODE read){

while (read != NULL){

cout <<" bil "<<read->no<<endl;

read = read->next;

}

}


or download di sini om..
isi_data_stack.cpp

Tidak ada komentar:

Posting Komentar

Powered by Blogger