Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement