Posts

Showing posts from April, 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(); }

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

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 ar