Saturday, June 25, 2016

Correctness Script

#include <stdio.h>
include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <iostream>
#include <conio.h>

using namespace studio;

strukt node {
   int nim;
   char name[20];
   float ipeka;
   
   struct node *next;
   struct node *prev;
};

struct node *head = NULL;
strukt node *last = NULL;
Struct node *current = NULL;

bool isEmpty(){
   return head == NULL;
}

void TampilForward(){
   struct node *ptr = head;
   if(isEmpty()){
      printf("Tidak Ada Data.\n);
      printf("Please, Masukan Data Pertama\n\n");
      printf("Tekan sembarang tombol untuk kembali ke Menu. \n");   
    system("pause>nul");
    system("clrscr");
      }

   while(ptr != NULL){       
      printf("NPM  : %d\n",pintar->npm);
      printf("Nama : %s\n",ptr->nama);
      printf("IPK  : %f\n",pinter->ipk);
      ptr = ptr->next;
      printf("-------------\n");     
   }
      system("pause>nul");
      system("cls");    
}

void SisipFirst(int npm, char nama[20], float ipk){
   struct node *link = (struct node*) malloc(sizeof(struct node));
   link->npm = npm;
   strncpy(link->nama, nama, sizeof(link->nama));
   link->ipk = ipk;
   
   if(isEmpty()){
      last = link;
   } else {
      head->prev = link;
   }

   link->next = head;
   head = link;
}

//insert link at the last location
void SisipLast(int npm, char nama[20], float ipk){

   //create a link
   struct node *link = (struct node*) malloc(sizeof(struct node));
   link->npm = npm;
   strncpy(link->nama, nama, sizeof(link->nama));
   link->ipk = ipk;
   
   if(isEmpty()){
      //make it the last link
//      head = link;
        insertFirst(npm, nama, ipk);
        return;
   }else {
      //make link a new last link
      last->next = link;    
      //mark old last node as prev of new link
      link->prev = last;
   }

   //point last to new last node
   last = link;

}

struct node* deleteNode(int npm){
   struct node* current = head;
   struct node* previous = NULL;

   if(isEmpty()){
      printf("DATA KOSONG.\n");
      return NULL;
   }

   while(current->npm != npm){
      if(current->next == NULL){
      printf("NPM TIDAK DITEMUKAN.\n");
         return NULL;
      } else {
         previous = current;
         current = current->next;            
      }
   }

   if(current == head) {
      head = head->next;
   } else {
      current->prev->next = current->next;
   }   

   if(current == last){
      last = current->prev;
   }else {
      current->next->prev = current->prev;
   }
   
   return current;
}

bool insertAfter(int npm, int newNpm, char nama[20], float ipk){
   struct node *current = head;
   
   if(isEmpty()){
      printf("DATA KOSONG.\n");
      return false;
   }

   while(current->npm != npm){
      if(current->next == NULL){
     printf("NPM TIDAK DITEMUKAN \n");
         return false;
      }else {          
         current = current->next;            
      }
   }
   
   struct node *newLink = (struct node*) malloc(sizeof(struct node));
   newLink->npm = newNpm;
   strncpy(newLink->nama, nama, sizeof(newLink->nama));
   newLink->ipk = ipk;

   if(current == last) {
      newLink->next = NULL;
      last = newLink;
   }else {
      newLink->next = current->next;        
      current->next->prev = newLink;
   }
   
   newLink->prev = current;
   current->next = newLink;
   return true;
}

int mainMain() {
   int menu;   
   do{
    printf("### MAIN MENU ###\n");
        printf("1. TAMBAH Data\n");
        printf("2. LIHAT Data\n");
        printf("3. SISIP After\n");
        printf("4. HAPUS\n");
        printf("5. KELUAR\n");
        printf("\nMenu : ");cin>>menu;
        system("cls");

        switch(menu){
            case 1:{
        printf("### TAMBAH DATA ###\n");
        int jmlData, npm;
        char nama[20];
        float ipk;
        printf("Masukan Jumlah Data : ");cin>>jmlData;
        system("cls");
        for (int i=1;i<=jmlData;i++) {
           cout<<"Npm    : ";cin>>npm;
           cout<<"Nama   : ";cin>>nama;
           cout<<"IPK    : ";cin>>ipk;
           insertLast(npm, nama, ipk);   
           printf("-------------\n");
           system("cls");
        }
                break;
            }
            case 2:{
        printf("### LIHAT DATA ###\n");
        displayForward();
                break;
            }
            case 3:{
        printf("### SISIP AFTER ###\n");
        int npm, newNpm;
        char nama[20];
        float ipk;
        cout<<"Insert After Npm :";cin>>npm;
        cout<<"Npm    : ";cin>>newNpm;
        cout<<"Nama   : ";cin>>nama;
        cout<<"IPK    : ";cin>>ipk;
                insertAfter(npm, newNpm, nama, ipk);
                system("cls");    
                break;
            }
            case 4:{
        printf("### HAPUS ###\n");
        int npm;
        cout<<"Npm    : ";cin>>npm;
        deleteNode(npm);
            system("cls");     
                break;
            }
        }
   }while(menu>=1 && menu<=4);{
        cout<<"----------------THANK YOU----------------";      
        system("pause>nul");
   };
   return 0;
}

would Read More..!

Tuesday, June 21, 2016

C++

Please download link bellow
<a href="https://drive.google.com/drive/folders/0BypmtwljyxxjS1lGSXdRYzV5TDA">try it</a>
<br>
try to corret them

would Read More..!

Friday, May 13, 2016

Quiz Aplikom

Sam...ari ini kita quiz ya ini soalnya ya... 

silahkan dikerjakan ya....!

would Read More..!

Thursday, May 12, 2016

Quiz test..Alpro2

Salam...
Soal quiz aplro ini dikerjakan di Lab B404 Gedung B UTama, sifat Open Book.waktu : 11 -12.40
Soal.
Diketahui Tabel Z berisi angka-angka sebagai berikut :
11 5 6 222 3 5 12 7 10 9 4 Soal 1:
a). Uraikan langkah-langkahnya dengan konsep DIvide and Conquer dan urutkan dengan metode Merge-Sort
b). Uraikan langkah-langkahnya dengan konsep DIvide and Conquer dan urutkan dengan metode Insertion-Sort
c). Uraikan langkah-langkahnya dengan konsep DIvide and Conquer dan urutkan dengan metode Quick-Sort
d). Uraikan langkah-langkahnya dengan konsep DIvide and Conquer dan urutkan dengan metode Selection-Sort
Soal 2:
Buat implementasi programnya dalam bahasa C++ (pilih salah poin [a,b,c atau d]).
Semoga sukses...!

would Read More..!

Materi Algoritma dan Pemrograman 2

Sialhkan download materi Alpro 2 disini disni aja

would Read More..!

Tuesday, May 03, 2016

Program BackTracking

#include <stdio.h>
#include <stdlib.h>

/* macro to define limits*/
#define MAX_X 4
#define MAX_Y 9

#define END_X 3
#define END_Y 8

/* define structure for one point
   with coordinate x and y */
typedef struct P{int x,y;};

/* functions to present path through matrix,
   check if next move is valid
   with backtrack technique */
void presentPath(P[],int);
int tryC(int m[][MAX_Y],int,int);
void checkPaths(int m[][MAX_Y],int,int,P[],int);

int
main()
{
/* declare start position and
   matrix we are searching paths*/
  int sX=0, sY=0,
      m[MAX_X][MAX_Y]=
     {
      {0,0,0,1,1,1,0,0,0},
      {1,1,0,0,0,0,0,0,0},
      {1,0,1,0,0,1,0,1,0},
      {0,0,1,1,0,1,1,1,0}
     };
 
  /* array that will serve to memorize the each path */
  P Path[MAX_X+MAX_Y+1];
 
  /* lets go and look for all paths */
  checkPaths(m,sX,sY,Path,0);

  return 0;
}

void
presentPath(P   Path[MAX_X+MAX_Y+1],
            int k)
{
  for(int i=0; i<k; i++)
    printf("%d, %d",Path[i].x,Path[i].y);
 
  printf("\n\n");
}

int tryC(int m[MAX_X][MAX_Y],int x, int y)
{return ((x>=0)&&(x<MAX_X)&&(y>=0)&&(y<MAX_Y)&&m[x][y]==0);}

void
checkPaths(int m[MAX_X][MAX_Y],
           int c_x, int c_y,
           P Path[MAX_X+MAX_Y+1],int l)
{
  /* will abandon path beyond wall
   and path where we hit the wall.
   your position is at the current
   x and y location*/
  if(!tryC(m,c_x,c_y)) return ;
 
  /* mark the path and memorize */
  m[c_x][c_y]=2;
  Path[l].x=c_x;Path[l].y=c_y;
 
  /* are we at the searched position
  or check new potential candidates */
  if((c_x==END_X)&&(c_y==END_Y))
      presentPath(Path,l+1);
  else
  {
      /* we will try to move down, right and down-right*/
      checkPaths(m,c_x+1,c_y+1,Path,l+1);
      checkPaths(m,c_x+1,c_y,Path,l+1);
      checkPaths(m,c_x,c_y+1,Path,l+1);
  }
 
  /* clear the position that has been marked */
  m[c_x][c_y]=0;
}


would Read More..!

Tuesday, April 19, 2016

Insertion_Sort_for_Practice

#include <iostream>
#include <conio.h>

using namespace std ;
int data[10],data2[10];
int n;

void tukar(int a, int b)
{
 int t;
 t = data[b];
 data[b] = data[a];
 data[a] = t;
}

void insertion_sort()
{
 int temp,i,j;
 for(i=1;i<=n;i++)
 {
  temp = data[i];
  j = i -1;
  while(data[j]>temp && j>=0)
  {
   data[j+1] = data[j];
   j--;
  }
 data[j+1] = temp;
 }
}
int main()
{
 cout<<"\t\t\t===PROGRAM INSERTION SORT===\n\n"<<endl;

 //Input Data
 cout<<"Masukkan Jumlah Data : ";
 cin>>n;
 cout<<"\n";
 for(int i=1;i<=n;i++)
 {
  cout<<"Masukkan data ke "<<i<<" : ";
  cin>>data[i];
  data2[i]=data[i];
 }

 insertion_sort();

 cout<<"\n\n";
 //tampilkan data
 cout<<"Data Setelah di Sort : ";
 for(int i=1; i<=n; i++)
 {
  cout<<" "<<data[i];
 }
 cout<<"\n\nSorting Selesai";
 getch();
}

would Read More..!

Monday, April 18, 2016

Merge_n_Insertion_sorting

// include file
#include <condefs.h>
#include <conio>
#include <iostream>
#include <fstream>

//dibatasi memori 52
#define MAXLIST 52
#define MAXINT (int) (2147483647)
using namespace std;
//struktur data kita tetap dan fleksible
typedef char item_type;
typedef struct node_tag;
{
  Item_type info;
  struct node_tag *next;
} Node_type;
typdedef struct list_ag
{
  Node_type *head;
  Node_type *tail;
} List_type;
//prototype fungsi operasi pada link list
void AddNode(List_type* ,Item_type , const int opt=0);
void DeleteNode(List_type , Item_type);
void Error (char*);
bool ExtractLine(Item_type& , Item_type);
void InitList(List_type* );
Node_type *MergeSort(Node_type *p);
List_type *InsertionSort (List_type *);
bool FindItem(const List_type* ,Item_type);
void Transverse(const List_type* ,void (*Visit) (ItemType));
void Visit(Item_type);
char Menu(void);
void CopyList(const List_type *, List_type *);
void BatchSort(List_type *list_ptr);
//var globaluntuk menghitng jumlah loop
int gloop1=0, gswap1=0, gcomp1=0;
int gloop2=0, gswap2=0, gcomp2=0;
//program utama
int main()
{   //variabel untuk list dan pointer ke list
    List_type list;List_type* list_ptr=&lst;
    List_type rlist;List_type* rlist_ptr=&rlist;
    List_type ilist, mlist;
    List_type *iSort=&ilist, *mSort=&mlist;
    int konter = 0; sring line; char ch='y';
    InitList(list_ptr); InitList(rlist_ptr);
    // ambil data dari file teks
    ifstream infile("bahasa.txt");
    //kita baca satu baris teks dari file
    while (getline(infile,line) && (konter < MAXLIST))
    {  //kita ambil karakter per karakter
      int i=0; //indeks karakter pada indeks dibaca
      //ambil satu karakter
      while ((i<line.length))) && (konter < MAXLIST))
      if (isalpha(line[i]))
         if (!FindItem(rlist_ptr,line[i])) //simpan ke list
              { konter++;AddNode(rlist_ptr,line[i]);
         i++; //ke karakter berikutnya
    }
}
Traverse(rlist_ptr,*Visit); //tampilkan daftar asli
//loop program utama
while (!(ch=='S' || ch =='\x1b'))
{  ch = Menu();     //tamplkan menu dan minta input
    switch (ch)
    {
      case '1': Traverse(rlist_ptr,*Visit);break;
      case '2': //sorting dengan insertion sort
         // kita kosongkan loop untuk perhitungan loop dll
         gswap1=0;gcomp1=0;gloop1=0; //nolkan variabel
         //the kita salin daftar asli le suatu dafta
         CopyList(rlist_ptr,list_ptr);
         //daftar hasil salinan ini yang kita urutkan
         iSort = InsertionSort(list_ptr); Transverse(iSort, *Visit);
         //dengan demikian daftar asli teta[ terjaga
         //tampilkan jumlah loop komparasi dan swap
         cout <<endl << :Insertion Sort -> ";
         cout << "Loop: " << gloop1 << "\tComp: " << gcomp1;
         cout << "tSwap:  << gswap1 << endl;break;
      case '3': //sortng dengan merge sort
         gswap2=0;gloop2=0;gcomp2;
         CopyList(rlist_ptr,list_ptr);
         mSort->head = MergeSort(list_ptr>head);
         cout << endl << "Merge Sort -> ";
         cout << "Loop: " << gloop2 << "\tComp: " << gcomp2;
         cout << "tSwap:  << gswap2 << endl;break;
      }
    }
    return(gethc());
}
char Menu(void)
{  // menampilkan menu
    char ch;
    cout << endl << "=== Metode Sorting --";
    cout << endl << "1 Telusur Daftar Asli "
    cout << endl << "2 Insertion Sort "
    cout << endl << "3 Merge Sort "
    cout << endl << "S Selesai <ESC> ";
    cout << endl << "MENU; "; ch=getch();cout << ch;
    return (ch);
}
void CopyList (const List_type *src, List_type *dat)
{  //menyalin daftar asli ke suaru daftar baru
    Node_type *q, *p, *r = src->head;
    InitList(dst);
    for (q=r;q;q=q->next)
    {  if ((p = (Node_type*) malloc(sizeof(Node_type))) == NULL)
             Error ("Memory kurang");
        else if ((dst->head == NULL) & (dst->tai == NULL))
        {  //head dan tail null menunjukan list masih kosong
            //karena itu penambahan terjadi utnuk head dan tail
            p->info =q->info;
            p->next = NULL;
            dst->tail=p;
            dst->head=p;
        }
        else  //sudah ada di node sebelumnya
        {  //kita tambahkan [adabagian be;akang list
            p->info =q->info;
            p->next = NULL;
            dst->tail=next = p;
            dst->tal = p;
        }
    }
}
/*Insertion sort : sorting list dengan insertionSort */
List_type *InsertionSort (List_type *list_ptr)
{  Node_type *head=list_ptr->head;
    Node_type *tail = head;
    Node_type *p, *q, *r;
    gcomp1++;
    if (head)
        while (tail->next)
        { gloop1++;
          q = tail->next;
          gcomp1++;
          if (q->info < head->info)
          {  gswap1++;
              tail->next = q->next;
              q->next = head;
              head =q;
          }
          else
          {  r = head;
              p = head->next;
              while (q->info > p->info)
              { gloop1++;
                 r = p;
                 p = p->next;
              }
              gcomp1++;
              if (q == p) tail = q;
              else
              { gswap1++;
                 tail->next = q->next;
                 q->next = p;
                 r->next = q
              }
          }
        }
        list_ptr->head = head;
    return list_ptr;
}
/*divide menmbagi dua dafar menajadi dua bagian...*/
Node_type *Divide(Node_type *p)
{  Node_type *q, *r;
    q = ;
    r = p->next->next;
    while(r)
    {  gloop2++;
        r = r->next;
        q = q->next;
        if (r)  r = r->next;
    }
    r = q->next;
    q->next  NULL;
    return r;
}

/*merge mengabbugkan dua subsit yg terurut
dan mengembalilakan pointer ke daftar hasil*/
Node_type *Merge(Node_type *p, Node_type *q)
{
  Node_type *head, *r;
  gcomp2++;
  if (!p || !q) Error("Daftar kosong"); gcomp2++;
  if (p->info <= q->info)
  {  gswap2++; head = p; p = p->next; }
  else
  {  gswap2++; head = q; q = q->next; }
  r = head;
  while (p && q)
  { gloop2++; gcomp2++;
     if (p->info <= q->info)
     {  gswap2++; r = r->next = p; p = p->next; }
     else
     {  gswap2++; r = r->next = q; q = q->next; }
  }
  gcomp2++;
  if (p) r->next = p; else r->next =q;
  return head;
}
/*MergeSort; mergeSort untukd aftar berakai lisklist*/
Node_type *MergeSort(Node_type *p)
{  Node_type *q, Node_type *head=p;
    gcomp2++;
    if (p && p->next)
    {  q = Divide(p); p = MergeSort(p);
        q = MergerSort(q); head=Merge(p,q);
    }
    retrn head;
}
void InitList(List_type* list_ptr)
{  list_ptr->head=NULL; list_ptr->tail=NULL;
}
void AddTail(List_type* list_ptr, Node_type* node_ptr)
{  node_ptr->next = NULL;
    list_ptr->tail->next = node_ptr;
    list_ptr->tail = node_ptr;
}
void AddHead(List_type* list_ptr, Node_type* node_ptr)
{  node_ptr->next = list_ptr->head;
    list_ptr->head = node_ptr;
}
void AddFirst(List_type* list_ptr, Node_type* node_ptr)
{  node_ptr->next = NULL;
    list_ptr->tail=node_ptr; list_ptr->tail->next=NULL;
    list_ptr->head=node_ptr; list_ptr->head->next=NULL;
    list_ptr->count++;
}
void AddNode(List_type* list_ptr, Item_type item, const int opt)
{  Node_ptr *p=NULL, *q=NULL;
    if ((p = (Node_type*) malloc(sizeof(Node_type))) == NULL)
      Error ("Memory kurang");
    else
    { p->info = item;
      if ((list_ptr->head == NULL) & (list_ptr->tail == NULL))
            AddFirst(list_ptr, p);
      else
         switch (opt)
         {  case 1: AddHeadlist_ptr, p);break;
             case 2: p->info = item;
                q = (Node_type*)list_ptr->head;
                if (q->next !=NULL)
                {  while ((q->next !=NULL && (item > q->next->info))
                        q=q->next;
                    if (q != NULL)
                    {  p->next = q->next; q->next = p;
                        list_ptr->count++;
                    }
                  else AddTail(list_ptr,p);break;
                }
             else AddTail(list_ptr,p);break;
          default: AddTail(list_ptr,p);
          }
     }
}
void DeleteNode(List_type* list_ptr, Item_type item)
{  Node_type *dp, *q;
   if (list_ptr->head == NULLL) Error ("List masih kosong");
   else if (ist_ptr->head->info == item)
   { dp = list_ptr->head; list_ptr->head = dp->next;
     free (dp);  list_ptr->count-=1;
   } else
   { q = list_ptr->head;
     while ((item != q->info) && !(q->next)) q=q->next;
     dp = q->next;
     if (dp)   
     { if (dp != list_ptr->tail) q->next = dp->next;
       else
       { list_ptr->tail = q;
         list_ptr->tail->next = NULL;
       }
       free (dp); list_ptr->count-=1;
     }
     else Error ("Item tidak ada !");
   }
}

bool FindItem(const List_type *list_ptr, Item_type item)
{ Node_type *p= list_ptr->head;
  while (p)
  { if (p->info == item) return true;
    p=p->next;
  }
  return false;
}

void Traverse(const List_type* list_ptr, void (*Visit) (Item_type))
{  Item_type item; Node_type* p = list_ptr->head;
   cout << "\n";
   while (p)
   { item = p->info; (*Vsit) (item);
     cout << "\t"; p=p->next;
   }
   cout << "\n";
}
void Visit(Item_type item) { cout << item;}











would Read More..!

Tuesday, April 12, 2016

Tugas_for_Aplro_DivideNconquer

#include <cstdlib>
#include <iostream>

using namespace std;

void minmax2(int A[], int i, int j, int &min, int &max ){
     /*
     Mencari nilai maksimum dan minimum di dalam tabel A yang
     berukuran n elemen secara Divide and Conquer.
     Masukan: tabel A yang sudah terdefinisi elemen-elemennya
     Keluaran: nilai maksimum dan nilai minimum tabel
     */
     int min1, min2, max1, max2,k;
     if(i==j){
              min=A[i];
              max=A[i];
              }
     else if(i==j-1){
          if(A[i]<A[j]){
                        max=A[j];
                        min=A[i];
                        }
          else{
               max=A[i];
               min=A[j];
               }
          }
     else{
          k=(i+j)/2;
          minmax2(A,i,k,min1,max1);
          minmax2(A,(k+1),j,min2,max2);
          if(min1<min2)min=min1;
          else min=min2;
          if(max1<max2)max=max2;
          else max=max1;
          }
     }

int main(int argc, char *argv[])
{
    system("color f2");
    system("title MinMax - Selasa, 29 Mei 2012 - dyasprogramming.blogspot.com");
   
    int A[100],n,i,j,min,max;
    cout<<"Mauskkan banyak data : ";
    cin>>n;
    for(int a=1;a<=n;a++){
            cout<<"Data ke-"<<a<<" : "; //Masukan data sebanyak n elemen
            cin>>A[a];
            }
    i=1;
    j=n;
   
    minmax2(A,i,j,min,max);
   
    cout<<"\nNilai max = "<<max<<endl;
    cout<<"Nilai min = "<<min<<endl<<endl;
   
    system("PAUSE");
    return EXIT_SUCCESS;
}


would Read More..!

Tuesday, March 08, 2016

Linked List--Menu

Well, here is example of Linked List for Student record...

#include <conio.h>
#include <iostream.h>
#include <malloc.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>

struct List{
    int NIM;
    char Nama[20];
    float IPK;
    List *Next;
    };

List *Head, *Baru, *PNow, *PAkhir, *HNow, *HBfr;
int Pilih;

int main()
{
 Head = new(List);
 Head -> Next = NULL;

 do
 {
  //clrscr();
  cout<<"\n*************************\n";
  cout<<"*  M E N U   U T A M A           *\n";
  cout<<"* 1. Add Data (di akhir)         *\n";
  cout<<"* 2. Add Data (di awal)          *\n";      
  cout<<"* 3. View Data                   *\n";
  cout<<"* 4. Search Data                 *\n";
  cout<<"* 5. Delete Data                 *\n";
  cout<<"* 6. Min & Max Value             *\n";
  cout<<"* 7. Exit                        *\n";
  cout<<"**********************************\n";
  cout<<"Pilih Menu [1/2/3/4/5/6/7] : ";cin>>Pilih;

  switch(Pilih)
  {
   case 1 : // Add Data (di akhir)
           {
            char Lagi ='Y';

            do
            {
             Baru = new (List);
             cout<<"Masukan NIM              : ";cin>>Baru -> NIM;
             cout<<"Masukan Nama             : ";cin>>Baru -> Nama;
             cout<<"Masukan IPK             : ";cin>>Baru -> IPK;
             PAkhir = NULL;
             PNow = Head -> Next;
             if(PNow == NULL)
             {
               //List masih kosong
               Baru -> Next = PNow;
               Head -> Next = Baru;
             }
             else
             {
               //List sudah berisi data
               //Cari posisi elemen terakhir
               while ((PNow != NULL) && (PNow -> NIM != Baru -> NIM))
               {
                PAkhir = PNow;
                PNow = PNow -> Next;
               }
               //Tambahkan data di akhir list
               if (PAkhir == NULL)
               {
                Baru -> Next = PNow;
                Head -> Next = Baru;
               }
               else
               {
                Baru -> Next = PNow;
                PAkhir -> Next = Baru;
               }
             }
             cout<<"Input data Lagi [Y/T] : ";cin>>Lagi;
            }while (Lagi == 'Y' || Lagi == 'y');
            getch();break;
           }
   case 2 : // Add Data (di awal)
            {
           }         
   case 3 : // View Data
           {
            if (Head->Next == NULL)
             cout<<"List Kosong\n";
            else
            {
             PNow = Head -> Next;
             while (PNow != NULL)
             {
              cout<<"NIM               : "<<PNow -> NIM<<endl;
              cout<<"Nama              : "<<PNow -> Nama<<endl;
              cout<<"IPK         : "<<PNow -> IPK<<endl;
              PNow = PNow -> Next;
             }
            }
            getch();break;
           }
   case 4 : // Search Data
          {
            int count = 1;
            int NIM_Cari;

            cout<<"Masukan NIM yang dicari : ";cin>>NIM_Cari;
            PNow = Head -> Next;
            if (PNow == NULL) {
             cout<<"Data Tidak Ditemukan karena List Kosong";
            }    
            else
            {
             while ((PNow != NULL) && (PNow -> NIM != NIM_Cari)) {
              PNow = PNow -> Next;
              count++;
             }
             if (PNow == NULL || PNow->NIM != NIM_Cari) {
              cout<<"Data Tidak Ditemukan.";
             }   
             else {
              cout<<"NIM           : "<<PNow -> NIM<<endl;
              cout<<"Nama              : "<<PNow -> Nama<<endl;
              cout<<"IPK             : "<<PNow -> IPK<<endl;
              cout<<NIM_Cari<<" ditemukan di posisi ke-"<<count<<endl;
             }
            }   
            getch();break;
           }
   case 5 : // Delete Data
          {
            int NIM_Hapus;
            char Jawab;
            int found = 0;

            cout<<"Masukan NIM yang akan dihapus : ";cin>>NIM_Hapus;
            HNow = Head -> Next;
            HBfr = NULL;
            if (HNow == NULL)
             cout<<"Data Tidak bisa dihapus karena List Kosong";
            else
            {
             while (HNow != NULL && !found)
             {
                 if (HNow->NIM == NIM_Hapus)
                     found = 1;
                 else {   
                     HBfr = HNow;
                     HNow = HNow -> Next;
                 }   
             }
             if (!found)
              cout<<"Data Tidak Ditemukan.";
             else
              {
               cout<<"Yakin Nilai : "<<NIM_Hapus<<" Akan dihapus [Y/T] :";cin>>Jawab;
               if (Jawab == 'T' || Jawab == 't')
                cout<<"Proses Penghapusan Nilai "<<NIM_Hapus<<" dibatalkan"<<endl;
               else
               {
                if (Jawab == 'Y' || Jawab == 'y')
                {
                 if (HBfr == NULL)
                  Head -> Next = HNow -> Next;
                 else
                  HBfr -> Next = HNow -> Next;
                }
               }
             }
            }
            getch();break;
          
           }
   case 6 : // Min & Max Value
          {
           }
   case 7 : cout<<"End of Application!!!";getch();break;
   default : cout<<"Salah pilih !!!";getch();break;
  }

 }while (Pilih >= 1 && Pilih <= 5);
 return 0;
}


remember to always write the code...,do not copy and paste,"practice makes perfect..".

would Read More..!

  © Blogger template 'External' by Ourblogtemplates.com 2008

Back to TOP