mengulangi data
#include<iostream>
using namespace std;
void main(){
struct node
{
int data; //will store information
node*next; //the reference to the next node
};
node*head=NULL; //create head
node*newNode; //create a temporary node
int nilai=10;
char ulang;
//add@front
newNode=(node*)malloc(sizeof(node));//allocate space for node
newNode->data=nilai;
newNode->next=head;
head=newNode;
do {
//add@front
newNode=(node*)malloc(sizeof(node));//allocate space for node
newNode->data=nilai;
newNode->next=head;
head=newNode;
//cetak isi linked list
cout<<"\n Isi List:";
node*temp;
temp=head;//transfer the address of 'temp' to 'head'
while(temp!=NULL)
{
cout<<temp->data<<"\t";//show the data in the linked list
temp=temp->next; //transfer the address if 'temp->next' to 'temp'
}
cout<<"\nulang lagi(y/t:";cin>>ulang;
nilai++;
}
while(ulang=='y');
system("pause");
}
Selasa, 07 Juni 2011
Langganan:
Posting Komentar (Atom)
Comments :
0 komentar to “linked list”
Posting Komentar