Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- struct TNode{
- int data;
- TNode *next;
- };
- // deklarasi variabel pointer head dan tail
- TNode *head;
- TNode *tail;
- void init(){
- head = NULL;
- }
- bool isEmpty(){
- if (head == NULL)
- return true;
- else
- return false;
- }
- void tambahDepan(int dataBaru){
- //buta node baru
- TNode *baru = new TNode;
- baru->data = dataBaru;
- baru->next = NULL;
- //cek apakah list kosang atau tidak
- if (isEmpty()){
- head = baru;
- head->next = NULL;
- }else{
- baru->next = head;
- head = baru;
- }
- cout<<"List berhasil ditambah"<<endl;
- }
- int main(){
- init();
- // inisialisasi();
- tambahDepan(5);
- cout<<head->data<<endl;
- tambahDepan(10);
- cout<<head->data<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement