Advertisement
Guest User

Jumlah Nilai - Krisna

a guest
Mar 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <curses.h>
  3.  
  4. typedef struct TNode {
  5.     int data;
  6.     TNode *next;
  7. };
  8.  
  9. TNode *head;
  10.  
  11. void initHead();
  12. int isEmpty();
  13. void insertDatas(int datas);
  14.  
  15. void initHead() {
  16.     head = NULL;
  17. }
  18.  
  19. int isEmpty() {
  20.     return (head == NULL) ? 1:0;
  21. }
  22.  
  23. void insertDatas(int datas) {
  24.     TNode *create;
  25.     create = new TNode;
  26.     create->data = datas;
  27.     create->next = NULL;
  28.  
  29.     if (isEmpty() == 1) {
  30.         head = create;
  31.         head->next = NULL;
  32.     } else {
  33.         create->next = head;
  34.         head = create;
  35.     }
  36.  
  37.     std::cout << "Data Berhasil Dimasukkan" << std::endl;
  38.  
  39. }
  40.  
  41. int main() {
  42.     std::cout << "Single List! \n" << std::endl;
  43.     initHead();
  44.  
  45.     std::cout << "Masukkan Data : \n" << std::endl;
  46.     int newData, i, total;
  47.  
  48.     for (i = 1; i <= 5; i++) {
  49.         std::cout << "Data Ke %d : " << i << std::endl;
  50.         std::cin >> newData;
  51.         insertDatas(newData);
  52.     }
  53.  
  54.     total += i+1;
  55.     std::cout << "Total Jumlah : " << total << std::endl;
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement