Skip to content

praktikum 6

Desember 4, 2010

#include
#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);
char 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<berikut)
out <

info <”;
out <berikut;
delete temp;
}
}

void List::sisip(char t)
{
cout << t <info;
Node* p = kepala;
kepala = kepala->berikut;
delete p;
return 1; //penghapusan sukses
}

void List::cetak()
{
for (Node* p = kepala; p; p=p->berikut)
cout <

info <”;
cout << “*\n\n”;
}

int main()
{
List x;
char data;
x.sisip(‘A’);
cout << x;
x.sisip(‘B’);
cout << x;
x.sisip(‘C’);
cout << x;
x.sisip(‘D’);
cout << x;
for (int i=0; i<5; i++){
x.hapus(data);
cout << data << ” dihapus dari list : “;
cout << x;
}
system(“PAUSE”);
return EXIT_SUCCESS;
}

From → Praktikum

Tinggalkan sebuah Komentar

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: