Contoh Program Insert Depan

#include <iostream.h>
#include <conio.h>

void cetak ();
struct node {
char data;
node*next;
};
node *head,*current,*tail;
void create ()
{
head =current = NULL;
}
void insert_depan (char data)
{
node *p;/*temporary node*/
p=new node;
p->data = data;
p->next = head;
head = current = p;
}
void cetak ()
{
node *p;
p=head;
while (p!=NULL)
{
cout<<p->data<<endl;
p=p->next;
}
}
void main ()
{
char c;
create ();
while (c!= '.')
{
cout<<"input data (A...Z) : ";
cin>>c;
insert_depan (c);
}
cout<<"cetak linked list";
cetak();
}

Hasil OutPutnya .

Post a Comment

0 Comments