Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cctype>
- #include "list.h"
- using namespace std;
- int main(){
- int menu = -1;
- List data;
- createList_103042310028(data);
- while(menu != 0){
- menu = createMenu_103042310028();
- switch(menu){
- case 0:
- {
- return 0;
- }
- case 1:
- AddNewMember_103042310028(data);
- break;
- case 2:
- printInfo_103042310028(data);
- break;
- case 3:
- {
- address name = getShortestName_103042310028(data);
- if(name != NULL){
- cout<< "Nama terpendek : " << info(name) << endl;
- }else{
- cout<< "Data kosong" << endl;
- }
- break;
- }
- case 4:
- {
- int total;
- char cari;
- cout << "Masukan max pencarian : ";
- cin >> total;
- cout << "Masukan huruf pertama yang dicari : ";
- cin >> cari;
- showFirstName_103042310028(data,total,cari);
- }
- break;
- }
- }
- }
- int createMenu_103042310028(){
- cout << "=====Menu=====" << endl;
- cout << "1. Input Data user" << endl;
- cout << "2. Show Data user" << endl;
- cout << "3. Get shortest name" << endl;
- cout << "4. Show First Name by input" << endl;
- cout << "0. Exit" << endl;
- cout << "==============" << endl;
- int input;
- cout <<" Pilih Menu : ";
- cin >> input;
- return input;
- }
- void printInfo_103042310028(List L){
- cout << "List member perpustakaan 103042310028 : "<< endl;
- address p = first(L);
- while(p!= NULL){
- cout << "==> " << info(p) << endl;
- p = next(p);
- }
- cout<<endl;
- }
- void AddNewMember_103042310028(List &data){
- string nameMember;
- int total;
- cout << "Masukan total member baru : ";
- cin >> total;
- for(int x=0;x<total;x++){
- cout << "Masukan data member baru ke - " << x+1 << " : ";
- cin >> nameMember;
- address adds = allocate_103042310028(nameMember);
- insertLast_103042310028(data,adds);
- }
- }
- void showFirstName_103042310028(List L,int n,char c){
- int current = 0;
- if(first(L) == NULL){
- cout << "Data Kosong" << endl;
- }else{
- cout << "List search : " << endl;
- address cur = first(L);
- while(cur!= NULL && current < n){
- if(toupper(c) == toupper(info(cur).front())){
- cout <<"==> "<< info(cur) << endl;
- current++;
- }
- cur = next(cur);
- }
- }
- }
- void createList_103042310028(List &L){
- first(L) = NULL;
- }
- address allocate_103042310028(string x){
- address p = new elmlist;
- info(p) = x;
- next(p) = NULL;
- return p;
- }
- address getShortestName_103042310028(List L){
- int lowestName = 0;
- address target;
- if(first(L) == NULL){
- return NULL;
- }else{
- address cur = first(L);
- lowestName = info(cur).length();
- target = cur;
- while(cur!= NULL){
- if(lowestName >= info(cur).length()){
- lowestName = info(cur).length();
- target = cur;
- }
- cur = next(cur);
- }
- }
- return target;
- }
- void insertFirst_103042310028(List &L, address P){
- next(P) = first(L);
- first(L) = P;
- }
- void insertLast_103042310028(List &L, address P){
- if(first(L) == NULL){
- insertFirst_103042310028(L,P);
- }else{
- address cur = first(L);
- while(next(cur)!= NULL){
- cur = next(cur);
- }
- next(cur) = P;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement