Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <stdio.h>
- #include <windows.h>
- #include <malloc.h>
- using namespace std;
- int pilih;
- int menu_Ari_S;
- int pilih_Ari_S();
- int add_baru_Ari_S();
- int add_dpn_Ari_S();
- int add_blk_Ari_S();
- int del_dpn_Ari_S();
- int del_blk_Ari_S();
- int tampil_Ari_S();
- struct simpul
- {
- char data_Ari_S[15];
- struct simpul *next;
- }*baru, *awal=NULL, *akhir=NULL,*hapus,*bantu;
- main()
- {
- do
- {
- system("cls");
- cout<<"================================================"<<endl;
- cout<<"Tugas 3 : Aplikasi Single Linked List (Individu)"<<endl;
- cout<<"================================================"<<endl;
- cout<<"MENU UTAMA :"<<endl;
- cout<<" 1. Menambah node di depan"<<endl;
- cout<<" 2. Menambah node di belakang"<<endl;
- cout<<" 3. Menghapus node di depan"<<endl;
- cout<<" 4. Menghapus node di belakang"<<endl;
- cout<<" 5. Menampilkan isi linked list"<<endl;
- cout<<" 6. Exit"<<endl;
- cout<<"------------------------------------------------"<<endl;
- cout<<"Inputkan Pilihan Anda : ";
- cin>>menu_Ari_S;
- pilih_Ari_S();
- } while(menu_Ari_S!=6);
- return 0;
- }
- int pilih_Ari_S()
- {
- if(menu_Ari_S==1)
- add_dpn_Ari_S();
- else if(menu_Ari_S==2)
- add_blk_Ari_S();
- else if(menu_Ari_S==3)
- del_dpn_Ari_S();
- else if(menu_Ari_S==4)
- del_blk_Ari_S();
- else if(menu_Ari_S==5)
- tampil_Ari_S();
- else
- {
- system("cls");
- cout<<"\n Terimakasih \n";
- getch();
- }
- }
- int add_baru_Ari_S()
- {
- system("cls");
- baru=(simpul*) malloc(sizeof(struct simpul));
- cout<<" Masukkan data : ";cin>>baru->data_Ari_S;
- baru->next=NULL;
- }
- int add_dpn_Ari_S()
- {
- system("cls");
- add_baru_Ari_S();
- if(awal==NULL)
- {
- awal=baru;
- akhir=baru;
- akhir->next=NULL;
- }
- else
- {
- baru->next=awal;
- awal=baru;
- }
- }
- int add_blk_Ari_S()
- {
- add_baru_Ari_S();
- if(awal==NULL)
- {
- awal=baru;
- }
- else
- {
- akhir->next=baru;
- }
- akhir=baru;
- akhir->next=NULL;
- }
- int del_dpn_Ari_S()
- {
- if (awal==NULL)
- {
- cout<<"\n Tidak ada data dalam linked list !!"<<endl;
- getch();
- system("cls");
- }
- else
- {
- hapus=awal;
- awal=awal->next;
- free(hapus);
- }
- }
- int del_blk_Ari_S()
- {
- if (awal==NULL)
- {
- cout<<"\n Tidak ada data dalam linked list !!"<<endl;
- getch();
- system("cls");
- }
- else if(awal==akhir)
- {
- hapus=awal;
- awal=awal->next;
- free(hapus);
- }
- else
- {
- hapus=awal;
- while(hapus->next!=akhir)
- hapus=hapus->next;
- akhir=hapus;
- hapus=akhir->next;
- akhir->next=NULL;
- free(hapus);
- }
- }
- int tampil_Ari_S()
- {
- if (awal==NULL)
- {
- cout<<"\n Tidak ada data dalam linked list !! "<<endl;
- }
- else
- {
- system("cls");
- cout<<"Menampilkan semua isi di dalam linked list : \n\n";
- bantu=awal;
- while(bantu!=NULL)
- {
- cout<<bantu->data_Ari_S<<" -> ";
- bantu=bantu->next;
- }
- cout<<"NULL";
- }
- getch();
- }
Add Comment
Please, Sign In to add comment