mengeluarkan data(nilai)
#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;
//add@front
newNode=(node*)malloc(sizeof(node));//allocate space for node
newNode->data=nilai;
newNode->next=head;
head=newNode;
nilai=50;
//add@front
newNode=(node*)malloc(sizeof(node));//allocate space for node
newNode->data=nilai;
newNode->next=head;
head=newNode;
//cetak isi linked 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'
}
system("pause");
}
Selasa, 07 Juni 2011
Langganan:
Posting Komentar (Atom)
Comments :
0 komentar to “linked list”
Posting Komentar