Jumat, 06 Juni 2014

program c++ pointer perulangan


#include <cstdlib>
#include <iostream>

class node {
  public :
        int data;
        node *berikut;
        };

using namespace std;

int main(int argc, char *argv[])
{
    node *A;
    A = new node;
    A->data = 1;
    A->berikut = NULL;
   
    node *B;
    B = new node;
    B->data = 2;
    B->berikut = NULL;
   
    node *C;
    C = new node;
    C->data = 3;
    C->berikut = NULL;
   
    node *D;
    D = new node;
    D->data = 4;
    D->berikut = NULL;
   
    A->berikut = B;
    B->berikut = C;
    C->berikut = D;
   
    cout << "Menggunakan perulangan untuk mencetak setiap data pada rantai\n";
 node *berikut = A;
 int i = 1;
 while (berikut != NULL) {
 cout << "Data ke-" << i << " > " << berikut->data << endl;
 i++;
 berikut = berikut->berikut;
}
    system("PAUSE");
    return EXIT_SUCCESS;
}

0 komentar:

Posting Komentar

Posting Lebih Baru Posting Lama Beranda

 

Followers

 

Blogroll

Templates by ridha ammi | CSS3 by David Walsh | Powered by {N}Code & Blogger