MATERI-MATERI MATA KULIAH SISTEM INFORMASI STMIK MDP

Pasang Iklan Gratis Disini !!!

ads ads ads ads

Selasa, 07 Juni 2011

Linked List

. Selasa, 07 Juni 2011

#include "iostream"
using namespace std;
void main () {
    struct node        //deklarasi node
    {
         int data;
             node *next;
    };

    node *head=NULL; // create head
    node *newNode ;  // create a temporary node

    int nilai;
    char ulang='y';
    do
    {
    cout<<"Masukkan Sebuah Nilai : ";cin>>nilai;
    // add@front
    newNode = (node*)malloc(sizeof(newNode)); //allocate space
    newNode ->data = nilai;   //store data (first field)
    newNode ->next = head;    //store the address of the point
    head = newNode;
    //display the information stored in linked list

    node*temp;
    temp=head; //transfer the address of 'temp' to 'head'
    cout<<" Isi List Sekarang : ";
    while (temp!=NULL)
    {
        cout<< temp->data<<"  "; // show the data in the linked list
        temp = temp->next; //transfer the address of 'temp->next' to 'temp-
        }
        cout<<"\n Ulangi Cari (Y/N) : ";cin>>ulang;
        nilai++;
    }
    while (ulang=='y');
    system ("pause");
}

SEMOGA BERMANFAAT

0 komentar:

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Posting Komentar

Tuliskan Komentar Disini..

Related Posts Plugin for WordPress, Blogger...
 
{Sistem Informasi} is proudly powered by Blogger.com | Template by : Sukriyadi | sukriyadi.blogspot.com