Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node{
- char nama[30];
- int nim;
- node *next;
- void print(){
- cout<<nama <<" \t "<<nim<<"\n";
- }
- };
- node *kepala,*ekor;
- void buat();
- void menu();
- void input();
- void cetak();
- void add_ke_list(node* data);
- bool list_kosong();
- int main(){
- buat();
- menu();
- }
- void menu(){
- int menu;
- char qn = 'y';
- do{
- cout<<"Menu "<<endl;
- cout<<"1. Input "<<endl;
- cout<<"2. Output (sorted)"<<endl;
- cout<<"3. Exit"<<endl;
- cout<<"Masukan pilihan : ";cin>>menu;
- switch(menu){
- case 1 :
- input();
- cout<<"kembali <y/n>";cin>>qn;
- break;
- case 2 :
- cetak();
- cout<<"kembali <y/n>";cin>>qn;
- break;
- case 3 :
- qn = 'y';
- cout<<"kembali <y/n>";cin>>qn;
- break;
- }
- }while(qn=='y');
- };
- void add_ke_list(node *data){
- cout<<"nama : ";cin>>data->nama;
- cout<<"nim : ";cin>>data->nim;
- node *bantu = kepala;
- if(!list_kosong()){
- while(bantu->next->nim < data->nim )
- bantu = bantu->next;
- data->next = bantu->next;
- bantu->next =data;
- }else{
- data->next =ekor;
- kepala->next = data;
- }
- }
- void input(){
- int jumlah;
- cout<<"masukan jumlah data : ";cin>>jumlah;
- for(int i =0; i< jumlah; i++){
- cout<<"data ke "<<i<<endl;
- add_ke_list(new node());
- }
- };
- bool list_kosong(){
- return kepala->next == ekor;
- }
- void buat(){
- //buat batas awal akhir
- kepala = new node();
- ekor = new node();
- kepala->nim= -1;
- ekor->nim = 99999999;
- kepala->next = ekor;
- };
- void cetak(){
- node *bantu = kepala;
- if( !list_kosong()){
- while((bantu = bantu->next) != ekor)
- bantu->print();
- }else{
- cout<<"list kosong"<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement