daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Mar 15th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct TNode{
  6.     int data;
  7.     TNode *next;
  8. };
  9.  
  10. // deklarasi variabel pointer head dan tail
  11. TNode *head;
  12. TNode *tail;
  13.  
  14. void init(){
  15.     head = NULL;
  16. }
  17. bool isEmpty(){
  18.     if (head == NULL)
  19.       return true;
  20.     else
  21.       return false;
  22. }
  23. void tambahDepan(int dataBaru){
  24.     //buta node baru
  25.     TNode *baru = new TNode;
  26.     baru->data = dataBaru;
  27.     baru->next = NULL;
  28.    
  29.     //cek apakah list kosang atau tidak
  30.     if (isEmpty()){
  31.         head = baru;
  32.         head->next = NULL;
  33.     }else{
  34.         baru->next = head;
  35.         head = baru;
  36.     }
  37.     cout<<"List berhasil ditambah"<<endl;
  38. }
  39.  
  40. int main(){
  41.     init();
  42. //  inisialisasi();
  43.     tambahDepan(5);
  44.     cout<<head->data<<endl;
  45.     tambahDepan(10);
  46.     cout<<head->data<<endl;
  47.    
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top