Linked List C++ Simple Code

/*PRORGRAM LINKED-LIST
_ _ _ _ _ _ _ _ _ _ _ _ */

#include
#include
#include
#include
class Node
{
public:
int x;
Node *ka;
};
void main()


{
clrscr();
int n,i;
Node *awal, *akhir, *temp;
awal = new Node;
akhir = awal;
cout<<"N = " ; cin>>n;
for ( i=1; i<=n; ++i)
{
temp = new Node;
temp->ka = NULL;
cout<<"Data ke " <<<" = ";
cin>> temp->x;

akhir->ka = temp;
akhir = temp;
}
cout<<"Seluruh Data1\n";
temp = awal->ka;
while (temp->ka !=NULL)
{
cout << temp->x <
temp = temp-> ka;
}
cout<< temp-> x <

cout<<"Seluruh Data2\n";
temp = awal->ka;
while (temp !=NULL)
{
cout << temp->x <
temp = temp-> ka;
}

int p;
cout<<"Hapus posisi ke " ; cin>>p;
Node *temp1, *temp2;
temp1 = awal;
for ( i= 1; itemp1=temp1->ka;
temp2 = temp1->ka;
temp1->ka = temp2->ka;
delete temp2;


cout<<"Seluruh Data\n";
temp = awal->ka;
while (temp !=NULL)
{
cout << temp->x <
temp = temp-> ka;
}
getch();
}

No comments:

Post a Comment