Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- struct node{
- string data;
- int har;
- node *next, *prev;
- }*head, *tail;
- void init(){
- head = NULL;
- }
- bool isempty() {
- if (head == NULL)
- return true;
- else return false;
- }
- void insertbelakang () {
- string x;
- int q;
- cout << "masukkan barang : ";
- cin >> x;
- cout << "masukkan harga : ";
- cin>>q;
- node *baru;
- baru = new node;
- baru -> data = x;
- baru -> har = q;
- baru -> next = NULL;
- baru -> prev = NULL;
- if (isempty()) {
- head = baru;
- tail = baru;
- tail -> next = NULL;
- tail -> prev = NULL;
- } else {
- tail -> next = baru;
- baru -> prev = tail;
- tail = baru;
- tail -> next = NULL;
- }
- }
- void cetak() {
- node *bantu = head;
- if (isempty()) {
- cout << "List kosong";
- } else {
- while (bantu != NULL) {
- cout << bantu -> data << "\t";
- cout << bantu -> har << "\n";
- bantu = bantu -> next;
- }
- }
- }
- int main()
- {
- init();
- int pilih, q;
- string x;
- menu :
- system("cls");
- cout << "*****Menu*****\n";
- cout << "1. Input Barang\n";
- cout << "2. tampilkan list barang\n";
- cout << "3. Keluar\n";
- cout<< endl;
- cout << "pilih : ";
- cin >> pilih;
- switch(pilih){
- case 1 :
- insertbelakang();
- system("pause");
- goto menu;
- break;
- case 2 :
- cetak();
- cout << endl << endl;
- system("pause");
- goto menu;
- break;
- case 3 :
- return 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement