7.06.2012

Tugas Modul 6 Linked List

Nama : Gatra Mustakim
NIM  : 201101004

Program Linked List 6.1 Nang Borlan


#include <stdio.h>
#include <conio.h>
#include <alloc.h>

void main(void)
{

int i;

struct ListEntry{
int number;
struct ListEntry *next;
}start, *node;


start.next=NULL;
node= &start;
for (i=1; i<=10; i++)
{
node->next=(struct ListEntry *) malloc(sizeof(struct ListEntry));
   node=node->next;
   node->number=i;
   node->next=NULL;
   }

node=start.next;
while (node)
{
printf("%d",node->number);
node=node->next;
}
getche();
}

Output Programnya













Program Linked List 6.2 Nang Borlan


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

#define nil NULL
#define info(P) P->info
#define next(P) P->next
#define first(L) (L)

typedef int infotype;
typedef struct telmlist *alamat;
typedef struct telmlist
{
infotype info;
   alamat next;
}elmtlist;

typedef alamat list;

void buatsenarai(list *L)
{
first (*L) = nil;
   }
   list nodbaru(int m)
   {
   list n;
   n = (list) malloc(sizeof(elmtlist));
   if (n!= NULL)
   {
    info(n) = m;
    next(n) = nil;
    }
    return n;
    }


      void sisipsenarai (list *L, list t, list p)
      {
      if (p==nil)
         {
         t->next=*L;
         *L=t;
         }
         else
         {
          t->next=p->next;
            p->next=t;
            }
            }

            void cetaksenarai (list L)
            {
            list ps;
            for (ps=L; ps!=nil; ps=ps->next)
            {
            cout<<" "<<info(ps)<<" -->";
            }
            cout<<" NULL"<<endl;
            }

      int main()
      {
      list pel;
         list n;
         int i,k,nilai;

         buatsenarai(&pel);
      cout<<" Masukkan Banyak data = ";
         cin>>k;
         for (i=1;i<=k;i++)
         {
          cout<<" Masukkan Data Senarai ke-"<<i<<" = ";
            cin>>nilai;
            n=nodbaru(nilai);
            sisipsenarai (&pel,n,NULL);
            }

            cetaksenarai(pel);
            getch();
            return 0;
            }

Output Programnya














Program Linked List 6.3 Nang Borlan


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

class node

{

public:

       int z;

       node *next;

};

void main ()

{

       clrscr ();

       int n,i;
       node*awal,*akhir,*temp;
       awal=new node;

       akhir=awal;

       cout<<"Masukan Datanya Bro =";

       cin>>n;

       for(i=1;i<=n;++i)

       {

              temp=new node;

              temp->next=NULL;

              cout<<"data"<<i<<"=";

              cin>>temp->z;

              akhir->next=temp;

              akhir=temp;

       }

       cout<<"seluruh data\n";

       temp=awal->next;

       while(temp->next!=NULL)

       {

              cout<<temp->z<<endl;

              temp=temp->next;

       }



       while(temp!=NULL)

       {

              cout<<temp->z<<endl;

              temp=temp->next;

       }

       int posisi;

       cout<<"Diapus posisi ke";

       cin>>posisi;

       node*temp1,*temp2;

       temp1=awal;

       for (i=1;i<posisi;++i)

              temp1=temp1->next;

       temp2=temp1->next;

       temp1->next=temp2->next;

       delete temp2;

       cout<<"Kabehan Data \n";

       temp=awal->next;

       while (temp!=NULL)

       {

              cout<<temp->z<<endl;

              temp=temp->next;

       }

       getche ();

}

Output Programnya













Program Linked List 6.1 Eclipse


//================================================
// Name        : 1.cpp
// Author      : Gatra Mustakim
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//================================================

#include <iostream>
#include <malloc.h>
#include <list>
using namespace std;

int main(int)
{

int i;

struct ListEntry{
int number;
struct ListEntry *next;
}start, *node;


start.next=NULL;
node= &start;
for (i=1; i<=10; i++)
{
   node->next=(struct ListEntry *) malloc(sizeof(struct ListEntry));
   node=node->next;
   node->number=i;
   node->next=NULL;
   }

node=start.next;
while (node)
{
cout<<node->number;
node=node->next;
}

return 0;
}

Output Programnya














Program Linked List 6.2 Eclipse


//==================================================
// Name        : 2.cpp
// Author      : Gatra Mustakim
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//===================================================

#include <iostream>
#include <stdlib.h>
#include <malloc.h>
#include <conio.h>
using namespace std;

#define nil NULL
#define info(P) P->info
#define next(P) P->next
#define first(L) (L)

typedef int infotype;
typedef struct telmlist *alamat;
typedef struct telmlist
{
infotype info;
   alamat next;
}elmtlist;

typedef alamat list;

void buatsenarai(list *L)
{
first (*L) = nil;
   }
   list nodbaru(int m)
   {
   list n;
   n = (list) malloc(sizeof(elmtlist));
   if (n!= NULL)
   {
    info(n) = m;
    next(n) = nil;
    }
    return n;
    }


      void sisipsenarai (list *L, list t, list p)
      {
      if (p==nil)
         {
         t->next=*L;
         *L=t;
         }
         else
         {
          t->next=p->next;
            p->next=t;
            }
            }

            void cetaksenarai (list L)
            {
            list ps;
            for (ps=L; ps!=nil; ps=ps->next)
            {
            cout<<" "<<info(ps)<<" -->";
            }
            cout<<" NULL"<<endl;
            }

      int main()
      {
      list pel;
         list n;
         int i,k,nilai;

         buatsenarai(&pel);
      cout<<" Masukkan Banyak data = ";
         cin>>k;
         for (i=1;i<=k;i++)
         {
          cout<<" Masukkan Data Senarai ke-"<<i<<" = ";
            cin>>nilai;
            n=nodbaru(nilai);
            sisipsenarai (&pel,n,NULL);
            }

            cetaksenarai(pel);
          getche();
            return 0;
            }

Output Programnya















Program Linked List 6.3 Eclipse


//============================================================================
// Name        : 3.cpp
// Author      : Gatra Mustakim
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <string.h>
#include <conio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;

class node

{

public:

       int z;

       node *next;

};

int main ()

{



       int n,i;
       node*awal,*akhir,*temp;
       awal=new node;

       akhir=awal;

       cout<<"Masukan Datanya Bro =";

       cin>>n;

       for(i=1;i<=n;++i)

       {

              temp=new node;

              temp->next=NULL;

              cout<<"data"<<i<<"=";

              cin>>temp->z;

              akhir->next=temp;

              akhir=temp;

       }

       cout<<"seluruh data\n";

       temp=awal->next;

       while(temp->next!=NULL)

       {

              cout<<temp->z<<endl;

              temp=temp->next;

       }



       while(temp!=NULL)

       {

              cout<<temp->z<<endl;

              temp=temp->next;

       }

       int posisi;

       cout<<"Diapus posisi ke";

       cin>>posisi;

       node*temp1,*temp2;

       temp1=awal;

       for (i=1;i<posisi;++i)

              temp1=temp1->next;

       temp2=temp1->next;

       temp1->next=temp2->next;

       delete temp2;

       cout<<"Kabehan Data \n";

       temp=awal->next;

       while (temp!=NULL)

       {

              cout<<temp->z<<endl;

              temp=temp->next;

       }

       getche ();

}

Output Programnya




Tugas Queue Modul 8

Nama : Gatra Mustakim
NIM : 201101004

Listing Program

//=======================================================
// Name        : Tugas.cpp
// Author      : Gatra Mustakim
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//=======================================================


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


int r,f,df;

int qu[50];


void enQueue(void);
void deQueue(void);
void Tampilkan(void);
using namespace std;
int main()
{
int k;
   for(k=0;k<50;k++)
   qu[k]=0;

   while(1)
   {
    cout<<endl;
      cout<<"========= Pilihan ==========="<<endl;
      cout<<"  1) enQueue "<<endl;
      cout<<"  2) deQueue "<<endl;
      cout<<"  3) Tampilkan Queue "<<endl;
      cout<<"  4) Keluar ! "<<endl;
      cout<<"=============================";
      cout<<endl;
      cout<<" Masukkan pilihan ( 1,2,3,4) dalam melakukan Queue : ";
      cin>>k;
      if (k==1) enQueue();
      if (k==2) deQueue();
      if (k==3) Tampilkan();
      if (k==4) break;
      }
      }
         //endmain



         void enQueue()
         {
        cout<<" Masukan elemen : ";
               cin>>qu[r];
               r++;
            }

            void deQueue()
            {
            cout<<" Pilihan yang anda pilih adalah Dequeue";
            qu[f]=1;
               f++;
               }

            void Tampilkan()
            {
            cout<<" Pilihan yang anda pilih adalah Tampilkan Queue";
            int i;
               cout<<endl<<" Queue : "<<endl;
               for(i=f;i<r;++i)
                cout<<qu[i]<<",";
                  cout<<endl<<" Pencet Sing Liyane . . .";
                  }

Output Programe




















Lanjutan Output


















Tugas Modul 7 STACK

Nama : Gatra Mustakim
NIM   : 201101004

Program STACK Nang Borlan


#include<iostream.h>
#include<conio.h>
#include<string.h>
#define MAX_STACK 10

struct STACK{
int top;
char data[10][10];
}; STACK tumpuk;

void inisialisasi()
{
tumpuk.top = -1;
   }
int IsFull()
{
if(tumpuk.top == MAX_STACK-1) return 1; else return 0;
   }

int IsEmpty()
{
if(tumpuk.top == -1) return 1; else return 0;
   }

void Push(char d[10])
{
tumpuk.top++;
   strcpy(tumpuk.data[tumpuk.top],d);
   }

void Pop()
{
cout<<" Data yang terambil = "<<tumpuk.data[tumpuk.top];
   tumpuk.top--;
   }

void TampilStack()
{
for(int i = tumpuk.top;i>=0;i--)
   {
    cout<<" Data : "<<tumpuk.data[i]<<endl;
      }
      }

void Clear()
{
tumpuk.top=-1;
   }

int main()
{
int pil;
   inisialisasi();
   char dt[10];

   do {
    cout<<" === Program Stack === \n";
    cout<<" 1. Push \n ";
      cout<<"2. Pop \n ";
      cout<<"3. Print \n ";
      cout<<"4. Clear \n ";
      cout<<"5. Exit \n ";
      cout<<"===================== \n";
      cout<<" Pilihan : ";
      cin>>pil;

      switch(pil)
      {
      case 1:
         if(IsFull() !=1){
         cout<<" Data = ";
         cin>>dt;
         Push(dt);
         }
          else cout<<" \n Stack Sampun penuh ! \n ";
          break;

         case 2:
         if(IsEmpty() !=1){
         Pop();
         }else
          cout<<"\n Stack Wis Kosong ! \n ";
            break;

         case 3:
         if(IsEmpty() !=1){
         TampilStack();
         }else
          cout<<"\n Stack Uwis Kosong ! \n ";
            break;

         case 4:
         Clear();
         cout<<"\n Stack Sampun Kosong ! \n ";
         break;

         }

   getche();
   }
   while(pil !=5);
   getche();
   }

Output Program Borlane























Program STACK Ning Eclipse

//=================================================
// Name        : 1.cpp
// Author      : Gatra Mustakim
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//=================================================



#include<iostream>
#include<cstring>
#define MAX_STACK 10
using namespace std;
#include<conio.h>

struct STACK{
int top;
char data[10][10];
}; STACK tumpuk;

void inisialisasi()
{
tumpuk.top = -1;
   }
int IsFull()
{
if(tumpuk.top == MAX_STACK-1) return 1; else return 0;
   }

int IsEmpty()
{
if(tumpuk.top == -1) return 1; else return 0;
   }

void Push(char d[10])
{
tumpuk.top++;
   strcpy(tumpuk.data[tumpuk.top],d);
   }

void Pop()
{
cout<<" Data yang terambil = "<<tumpuk.data[tumpuk.top];
   tumpuk.top--;
   cout<<endl;
   }

void TampilStack()
{
for(int i = tumpuk.top;i>=0;i--)
   {
    cout<<" Data : "<<tumpuk.data[i];
    cout<<endl;
  }
      }

void Clear()
{
tumpuk.top=-1;
   }

int main()
{
int pil;
   inisialisasi();
   char dt[10];

   do {
 cout<<" =====Program STACK==== \n";
     cout<<" 1. Push \n ";
      cout<<"2. Pop \n ";
      cout<<"3. Print \n ";
      cout<<"4. Clear \n ";
      cout<<"5. Exit \n ";
      cout<<" ====================== \n";
      cout<<" Pilihan : ";
      cin>>pil;

      switch(pil)
      {
      case 1:
         if(IsFull() !=1){
         cout<<" Data = ";
         cin>>dt;
         Push(dt);
         }
          else cout<<" \n Stack penuh ! \n ";
          break;

         case 2:
         if(IsEmpty() !=1)
         Pop();
         else
          cout<<"\n Stack Kosong ! \n ";
            break;

         case 3:
         if(IsEmpty() !=1)
         TampilStack();
         else
          cout<<"\n Stack Kosong ! \n ";
            break;

         case 4:
         Clear();
         cout<<"\n Stack Sudah Kosong ! \n ";
         break;

         }

      //getche();
   }
   while(pil !=5);
   return 0;
   }


Output Program Nang Eclipse























6.03.2012

Tugas Array Dengan SwitchCase dan While

1. Array SwitchCase

//============================================================================
// Name : Kuis_Array_2D_3D_Case_while.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================


#include
using namespace std;

int main()

{
awal:
int pilihan;


cout<<" Program Array \n ";
cout<<" \n 0. Array 2D ";
cout<<" \n 1. Array 3D ";
cout<<" \n 2. Exit ";
cout<<" \n =============================== \n ";
cout<<" \n Pilihan : \t ";
cin>>pilihan;
switch(pilihan)

{

case 0:

{
int huruf_A[8] [50]=
{
{1,1,1,1,1,1,1,0 ,0,1,1,1,1,1,0,0 ,1,1,1,1,1,1,1,0 ,1,1,1,1,1,1,1,0 ,0,1,1,1,1,1,0,0},
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0,0,0,0,0,0}},

{{1,1,1,1,1,1,1,0 },
{0,0,0,1,1,0,0,0},
{0,0,0,1,1,0,0,0},
{0,0,0,1,1,0,0,0},
{0,0,0,1,1,0,0,0},
{0,0,0,1,1,0,0,0},
{0,0,0,1,1,0,0,0},
{0,0,0,0,0,0,0,0}},

{{1,1,1,1,1,1,1,0},
{1,1,0,0,0,0,1,0},
{1,1,0,0,0,0,1,0},
{1,1,1,1,1,1,1,0},
{1,1,1,1,0,0,0,0},
{1,1,0,1,1,0,0,0},
{1,1,0,0,1,1,0,0},
{0,0,0,0,0,0,0,0}},

{{0,1,1,1,1,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{1,1,1,1,1,1,0,0},
{1,1,0,0,0,1,0,0},
{1,1,0,0,0,1,0,0},
{1,1,0,0,0,1,0,0},
{0,0,0,0,0,0,0,0}}
};

int i,j,k;

for (i=0;i<5;i++)
{
for (j=0;j<8;j++)
{
for(k=0;k<8;k++)
if(huruf[i] [j] [k]==1)
cout<<"0";
else
cout<<"\x20";
cout< }
cout< }
return 0;
break;

}


}
return 0;
}
===============================================================================

Hasil Output







2.Array While

Listing Program

//============================================================================
// Name : Kuis_Array_2D_3D_While.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include
using namespace std;

int main()
{
int pilih;
int huruf_A[8] [50]=
{
{1,1,1,1,1,1,1,0 ,0,1,1,1,1,1,0,0 ,1,1,1,1,1,1,1,0 ,1,1,1,1,1,1,1,0 ,0,1,1,1,1,1,0,0},
{1,0,0,0,0,0,0,0 ,0,1,0,0,0,1,0,0 ,0,0,0,1,1,0,0,0 ,1,1,0,0,0,0,1,0 ,0,1,0,0,0,1,0,0},
{1,0,0,0,0,0,0,0 ,0,1,0,0,0,1,0,0 ,0,0,0,1,1,0,0,0 ,1,1,0,0,0,0,1,0 ,0,1,0,0,0,1,0,0},
{1,0,0,0,0,0,0,0 ,1,1,1,1,1,1,1,0 ,0,0,0,1,1,0,0,0 ,1,1,1,1,1,1,1,0 ,1,1,1,1,1,1,0,0},
{1,0,0,1,1,1,1,0 ,1,1,0,0,0,0,1,0 ,0,0,0,1,1,0,0,0 ,1,1,1,1,0,0,0,0 ,1,1,0,0,0,1,0,0},
{1,0,0,0,0,1,1,0 ,1,1,0,0,0,0,1,0 ,0,0,0,1,1,0,0,0 ,1,1,0,1,1,0,0,0 ,1,1,0,0,0,1,0,0},
{1,1,1,1,1,1,1,0 ,1,1,0,0,0,0,1,0 ,0,0,0,1,1,0,0,0 ,1,1,0,0,1,1,0,0 ,1,1,0,0,0,1,0,0},
{0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0},
};


while (1)
{
cout<<" Program Array ";
cout<<"\n 0. Array 2D ";
cout<<"\n 1. Array 3D ";
cout<<"\n Pilih : ";
cin>>pilih;
if(pilih==0)
{
int i,j;
for(i=0; i<8; i++)
{
for(j=0; j<50; j++)
if(huruf_A[i][j]==1)
cout<<"0";
else
cout<<'\x20';
cout< }
return 0;
break;
}

while (1)

{

if (pilih==1)
{
int huruf[5] [8] [8]=
{
{{1,1,1,1,1,1,1,0},
{1,0,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0},
{1,0,0,1,1,1,1,0},
{1,0,0,0,0,1,1,0},
{1,1,1,1,1,1,1,0},
{0,0,0,0,0,0,0,0}},

{{0,1,1,1,1,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{1,1,1,1,1,1,1,0 },
{1,1,0,0,0,0,1,0 },
{1,1,0,0,0,0,1,0 },
{1,1,0,0,0,0,1,0},
{0,0,0,0,0,0,0,0}},

{{1,1,1,1,1,1,1,0 },
{0,0,0,1,1,0,0,0},
{0,0,0,1,1,0,0,0},
{0,0,0,1,1,0,0,0},
{0,0,0,1,1,0,0,0},
{0,0,0,1,1,0,0,0},
{0,0,0,1,1,0,0,0},
{0,0,0,0,0,0,0,0}},

{{1,1,1,1,1,1,1,0},
{1,1,0,0,0,0,1,0},
{1,1,0,0,0,0,1,0},
{1,1,1,1,1,1,1,0},
{1,1,1,1,0,0,0,0},
{1,1,0,1,1,0,0,0},
{1,1,0,0,1,1,0,0},
{0,0,0,0,0,0,0,0}},

{{0,1,1,1,1,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{1,1,1,1,1,1,0,0},
{1,1,0,0,0,1,0,0},
{1,1,0,0,0,1,0,0},
{1,1,0,0,0,1,0,0},
{0,0,0,0,0,0,0,0}}
};

int i,j,k;

for (i=0;i<5;i++)
{
for (j=0;j<8;j++)
{
for(k=0;k<8;k++)
if(huruf[i] [j] [k]==1)
cout<<"0";
else
cout<<"\x20";
cout< }
cout< }
return 0;
}
}

return 0;
}
}
==================================================================================

Hasil Output While