#include
using namespace std;
class node{
friend class list;
friend ostream& operator<<(ostream&, const list&);
public:
node(char &t,node *p):info(t),berikut(p){}
protected:
char info;
node *berikut;
};
class list{
friend ostream& operator<<(ostream&,const list&);
public:
list():kepala(0){}
~list();
void sisip(char t);
int hapus(char& t);
int hapusbelakang(char& t);
int kosong(){return(kepala==0);}
void cetak();
protected:
node *kepala;
node *nodebaru(char& t, node*p){
node *q=new node(t,p);return q;}
};
ostream& operator<<(ostream& out, const list& k){
for(node* p=k.kepala;p;p=p->berikut)
out<
return out;
}
list::~list(){
node* temp;
for(node* p=kepala;p;){
temp=p;
p=p->berikut;
delete temp;
}
}
void list::sisip(char t){
cout<
node *p=nodebaru(t,kepala);
kepala=p;
}
int list::hapus(char& t){
if(kosong())return 0;
t=kepala->info;
node* p=kepala;
kepala=kepala->berikut;
cout<
delete p;
return 1;
}
int list::hapusbelakang(char& t){
if(kosong())return 0;
t=kepala->info;
node*p=kepala;
kepala=kepala->berikut;
delete p;
return 1;
}
void list::cetak(){
for(node* p=kepala;p;p=p->berikut)
cout<
}
int main(int argc, char *argv[])
{
list x;
char data;
x.sisip('c');
cout<
x.sisip('b');
cout<
x.sisip ('e');
cout<
x.sisip('a');
cout<
x.sisip('d');
cout<
// for(int i=0;i<6;i++){
// x.hapus(data);
// cout<<<" dihapus dari list: ";
// cout<
// }
system("PAUSE");
return EXIT_SUCCESS;
}
Tidak ada komentar:
Posting Komentar