Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <curses.h>
- typedef struct TNode {
- int data;
- TNode *next;
- };
- TNode *head;
- void initHead();
- int isEmpty();
- void insertDatas(int datas);
- void initHead() {
- head = NULL;
- }
- int isEmpty() {
- return (head == NULL) ? 1:0;
- }
- void insertDatas(int datas) {
- TNode *create;
- create = new TNode;
- create->data = datas;
- create->next = NULL;
- if (isEmpty() == 1) {
- head = create;
- head->next = NULL;
- } else {
- create->next = head;
- head = create;
- }
- std::cout << "Data Berhasil Dimasukkan" << std::endl;
- }
- int main() {
- std::cout << "Single List! \n" << std::endl;
- initHead();
- std::cout << "Masukkan Data : \n" << std::endl;
- int newData, i, total;
- for (i = 1; i <= 5; i++) {
- std::cout << "Data Ke %d : " << i << std::endl;
- std::cin >> newData;
- insertDatas(newData);
- }
- total += i+1;
- std::cout << "Total Jumlah : " << total << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement