# data[].attributes.body
#include<iostream>
using namespace std;

struct NODE{
int number;
NODE * next;
};
NODE *headptr;

void senaraikosong(){

headptr= NULL;

}

void insertdata(int nilai){

NODE * newptr, *currptr, *prevptr;

newptr = new NODE;
newptr->number = nilai;
newptr->next = NULL;

if (headptr==NULL){
headptr = newptr;
}

else{
prevptr = NULL;
currptr = headptr;

while((currptr!=NULL) && (nilai > currptr->number)){
prevptr = currptr;
currptr=currptr->next;
}

if (prevptr== NULL){
newptr->next = headptr;
headptr = newptr;
}
else{
newptr->next = currptr;
prevptr->next = newptr;

}

}

}

void papar(){

NODE *currptr;

currptr = headptr;

if (headptr==NULL)
cout<<"senarai kosong";

else{

while (currptr!= NULL){

cout<<currptr->number<<" ->";

currptr= currptr->next;

}
}

}

void deleteData(){
int data;
NODE *temptr, *currptr, *prevptr;

cout<<"data mana?";
cin>>data;

if (headptr == NULL){
cout<<"senarai kososng";}
else{
currptr = headptr;
prevptr = NULL;

while((currptr!=NULL) && (data != currptr->number)){
prevptr = currptr;
currptr= currptr->next;
}

if (prevptr== NULL){
temptr = headptr;
headptr= headptr->next;
delete temptr;

}else if (currptr== NULL)
cout<<"Tiada dalam senarai";

else {
temptr = currptr;
prevptr->next = currptr->next;
delete temptr;
}
}
}

void removeALL(){
NODE *temptr;

while(headptr!=NULL){
temptr= headptr;
headptr= headptr->next;
delete temptr;
}

}

int main(){

int value;
char response;

cout<<" MENU SENARAI TERPAUT: 'Y'- yes 'N' - NO";
cin>>response;
senaraikosong();

while ( response == 'Y'){
cout<< "masukk data";
cin>>value;
insertdata(value);

cout<<" MENU PAPAR SENARAI TERPAUT: 'Y'- yes 'N' - NO";
cin>>response;
papar();

cout<<"Anda ingin teruskan 'Y'- yes 'N' - NO";
cin>>response;

}

deleteData();
papar();

removeALL();
papar();

}

# data[].attributes.body
#include<iostream>
using namespace std;

struct NODE{
int number;
NODE * next;
};
NODE *headptr;

void senaraikosong(){

headptr= NULL;

}

void insertdata(int nilai){

NODE * newptr, *currptr, *prevptr;

newptr = new NODE;
newptr->number = nilai;
newptr->next = NULL;

if (headptr==NULL){
headptr = newptr;
}

else{
prevptr = NULL;
currptr = headptr;

while((currptr!=NULL) && (nilai > currptr->number)){
prevptr = currptr;
currptr=currptr->next;
}

if (prevptr== NULL){
newptr->next = headptr;
headptr = newptr;
}
else{
newptr->next = currptr;
prevptr->next = newptr;

}

}

}

void papar(){

NODE *currptr;

currptr = headptr;

if (headptr==NULL)
cout<<"senarai kosong";

else{

while (currptr!= NULL){

cout<<currptr->number;

currptr= currptr->next;

}
}

}

int main(){

senaraikosong();

insertdata(12);
insertdata(32);
papar();

}