Showing posts with label S. Data. Show all posts
Showing posts with label S. Data. Show all posts

Thursday, November 24, 2011

Contoh Program Pohon

 Silahkan dicoba
#include <iostream>
#include <deque>
#include <climits>
using namespace std;

struct Tree
{
 char data;
 Tree *left;
 Tree *right;  
 Tree *parent;  
};

Tree* lookUp(struct Tree *node, char key)
{

Read More...... Read more...

Antrian dengan linklist


Contoh antrian dengan linklist
#include <stdio.h>
#include <stdlib.h>

struct node
{
 int data;
 node *next;
};
typedef struct node node_t;

node_t *head = NULL;

void push(int n)
{
 node_t *newNode = (node_t *)malloc(sizeof(node_t));
 newNode->data = n;
 newNode->next = NULL;

Read More...... Read more...

Saturday, November 12, 2011

Link list menggunakan class

#include <iostream>
#include <string>
using namespace std;

class list
{
public:
 struct node {
  int id;
  string name;
  struct node *next;
 } *head, *tail, *ptr; 

 list():head(NULL),tail(NULL){} // constructor 
 ~list();   // destructor

Read More...... Read more...

Friday, November 11, 2011

Link list circular (loop)


Didalam kode ini berisi
 1. menambahkan node
 2. fungsi pengembalian pada list
 3. membuat list circular (loop)
 4. rekursif 

#include <iostream>
using namespace std;

struct Node
{
 int data;
 Node * next;
};

Read More...... Read more...

Thursday, November 10, 2011

Stack menggunakan linklist

Contoh program stack ini menggunakan linklist dan data terstruktur


#include <iostream<

using namespace std;

typedef struct Element
{
 void *data;
 struct Element *next;
} Element;

bool push(Element **top, void *data)
{
 Element *elem = new Element;
 if(!elem) return false;

 elem->data = data;
 elem->next = *top;
 *top = elem;
 return true;
}

bool createStack(Element **top)
{
 *top = NULL;
 return true;
}

bool pop(Element **top, void **data )
{
 Element *elem;
 if( !(elem = *top) ) return false;

 *data = elem->data;
 *top = elem->next;
 delete elem;
 return true;
}

bool deleteStack(Element **top)
{
 Element *elem;
 while(*top) {
  elem = (*top)->next;
  delete *top;
  *top = elem;
 }
 return true;

}

void printStack(Element *top) 
{
 if(top==NULL) {
  cout << "Empty!" << endl;
 }
 Element *cur = top;
 while(cur) {
  cout << *(static_cast<int *>(cur->data)) << " ";
  cur = cur->next;
 }
 cout << endl << endl;
}

int main()
{
 Element *head;
 createStack(&head);
 int n1 = 10, n2 = 20, n3 = 30, n4 = 40, n5 = 50;
 push(&head, &n1);
 push(&head, &n2);
 push(&head, &n3);
 push(&head, &n4);
 push(&head, &n5);

 printStack(head);

 void * n;
 pop(&head, &n);
 cout << "popped " << *(static_cast<int*>(n)) << endl;
 pop(&head, &n);
 cout << "popped " << *(static_cast<int*>(n)) << endl;
 cout << endl;

 printStack(head);

 cout << "deleting stack..." << endl;
 deleteStack(&head);
 printStack(head);
}

Read More...... Read more...

Link list menggunakan template

ini contoh linklist circular menggunakan template
#include <iostream>
#include <string>

using namespace std;

template <class T>
class LinkedList
{
private:
 struct node
 {
  T data;
  node * next;
 } *head;

public:

Read More...... Read more...

Contoh Link list

Ini adalah contoh linklist
silahkan dicoba

#include <iostream>

using namespace std;

struct Node {
 int data;
 Node* next;
};

// only for the 1st Node
void initNode(struct Node *head,int n){
 head->data = n;
 head->next =NULL;
}

// apending
void addNode(struct Node *head, int n) {
 Node *newNode = new Node;
 newNode->data = n;
 newNode->next = NULL;

 Node *cur = head;
 while(cur) {
  if(cur->next == NULL) {
   cur->next = newNode;
   return;
  }
  cur = cur->next;

Read More...... Read more...

Tuesday, November 1, 2011

Program Pointer


Contoh program pointer

#include <iostream>  
using namespace std;  

enum Type  {  
   INT,  
   FLOAT,  
   STRING,  
 };  

void Display(void *pVoid, Type eType)  {    
   switch (eType)  {  
 case INT:  
   cout << *(int*)pVoid << endl;  
  break;  

Read More...... Read more...

Source code program C menghitung nilai kombinasi Dan Permutasi

Berikut ini merupakan source code bahasa C untuk membuat program penghitung nilai dari kombinasi bilangan

# include <stdio.h>
long int faktorial (unsigned int n)
{
if(n==1||n==0)
return 1;
else
return n*faktorial (n-1);
}
int main()
{
int a,b;
long int hasil;
printf("\t Menghitung Rumus Kombinasi\n\n");
printf("Masukkan nilai a = ");

Read More...... Read more...

Wednesday, October 12, 2011

Contoh Program Antrian


Source Code C++:
#include <iostream.h>
#include <conio.h>

int main()
{
    int cek=0, data[20], x, hapus;
    char pil;
    do {
           
            cout<<"1. Tambah Antrian"<<endl;
            cout<<"2. Hapus Antrian"<<endl;
            cout<<"3. Lihat Antrian"<<endl;
            cout<<"4. Keluar"<<endl;
         cout<<endl;
            cout<<"Silahkan masukkan pilihan anda = ";
            pil=getche();
         cout<<endl;
if(pil!='1' && pil !='2' && pil !='3' && pil!='4' )
          cout<<"Anda salah mengetikkan inputan";
            else
            {
                if(pil=='1')   //PUSH
                {
                    if(cek==20)
                        cout<<"Antrian Penuh";
                    else
                    {
                    cout<<"Masukkan nilai = ";
               cin>>x;
                        data[cek]=x;
                        cek++;
                    }
                }
                else
                {
                    if(pil=='2')     //POP
                    {
                        if(cek==0)
                            cout<<"Antrian kosong";
                        else
                        {
                            hapus=data[0];
                            for(int v=0;v<cek;v++)
                                data[v]=data[v+1];
                            data[cek-1]=NULL;
                            cek--;
                       cout<<"Data dengan nilai "<<hapus<<" terhapus";
                        }
                        getch();
                    }
                    else
                    {
                        if(pil=='3')   //CEK DATA
                        {
                            if(cek==0)     
                                cout<<"Antrian Kosong";

                            else
                            {
                                cout<<endl;
                                for(int z=0;z<cek;z++)
                                {
                                    cout<<" | ";
                                    cout<<" "<<data[z];
                                    cout<<" | ";
                                }

                            }
                            getch();
                            return 0;
                        }
                    }
                }
            }

    }while(pil!='4');
}

Read More...... Read more...

Lorem Ipsum

Lorem Ipsum




Lorem

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP