interface and toc

Oktober 7, 2008 at 6:03 am | In Uncategorized | Leave a Comment

ini yang udah aku buat….

pertama sort.h

/* file : sort.h*/

#ifndef sort_H
#define sort_H
#define IdxMin 1
#define IdxMax 100

typedef struct
{
  int DD;
  int MM;
  int YYYY;
} tanggal;

typedef struct
{ char name[];
  int Size;
  tanggal date;
  jam J;
} data;

void SortName (data *N);

void SortDate (data *N);

void SortUkuran (data *N);

#endif

lalu file sort.c

/* file : sort*/

#include <stdio.h>
#include <stdlib.h>
#include “sort.h”
#include “jam.h”

void SortName ()
{
    char *name[];/*array of namafile*/
    char *temp;
    int x,a,b;
   
    for(a=0;a<IdxMax-1;a++)
        for(b=a+1;b<IdxMax;b++)
        {
            if(*name[a] > *name[b]) /* masih ragu dengan array string ini,
                                    apa bisa kya gini*/
            {
                temp = names[a];
                names[a] = names[b];
                names[b] = temp;
            }
        }

    for(x=0;x<IdxMax;x++)
        printf(“%s\n”,names[x]);
}        
void SortDate ()
/* pakai insertion sort*/
{   
 /* KAMUS LOKAL */
 int i;
 int Pass;
 int Temp;
 data *N;
 
 /* ALGORITMA */
 for (Pass = IdxMin+1; Pass <= GetNeff ((*N)); Pass ++)
 {
  Temp = GetElmt (((*N).((*J).DD)), Pass);
  i = Pass-1;
  
  while ((Temp <= GetElmt (((*N).((*J).DD)), i)) && (i > IdxMin))
  {
   SetElmt (&((*N).((*J).DD)), i+1, GetElmt (((*N).((*J).DD)), i));
   i–;
  }
  
  if (Temp >= GetElmt (((*N).((*J).DD)), i))
  {
   SetElmt (&((*N).((*J).DD)), i+1, Temp);
  }
  else /* Temp < GetElmt(((*J).DD), i) */
  {
   SetElmt (&((*N).((*J).DD)), i+1, GetElmt (((*N).((*J).DD)), i));
  }
  
  SetElmt (&((*N).((*J).DD)), i, Temp);
 }
}

void SortUkuran ()
{   
 /* KAMUS LOKAL */
 int i;
 int Pass;
 int Temp;
 data *N;
 
 /* ALGORITMA */
 for (Pass = IdxMin+1; Pass <= GetNeff ((*N)); Pass ++)
 {
  Temp = GetElmt (((*N).Size), Pass);
  i = Pass-1;
  
  while ((Temp <= GetElmt (((*N).Size), i)) && (i > IdxMin))
  {
   SetElmt (&((*N).Size), i+1, GetElmt (((*N).Size), i));
   i–;
  }
  
  if (Temp >= GetElmt (((*N).Size), i))
  {
   SetElmt (&((*N).Size), i+1, Temp);
  }
  else /* Temp < GetElmt(((*J).DD), i) */
  {
   SetElmt (&((*N).Size), i+1, GetElmt (((*N).Size), i));
  }
  
  SetElmt (&((*N).Size), i, Temp);
 }
}

ketiga stack.h

/* file : stack.h*/

#ifndef stack_H
#define stack_H
#include “boolean.h”
#define Nil 0

typedef int infotype;
typedef int address;

typedef struct
{ infotype *T;
  address TOP;
  int Size;
} Stack;

#define Top(S) (S).TOP
#define InfoTop(S) (S).T[(S).TOP]
#define Size (S) (S).Size

boolean IsEmpty (Stack S);

void Destruct (Stack *S);

void Push (Stack *S, infotype X);

void Pop (Stack *S, infotype *X);

int MakeFile (Stack S);

#endif

 

keempat stack.c

/* file : stack.c*/

#include <stdlib.h>
#include <stdio.h>
#include “stack.h”

boolean IsEmpty (Stack S)
{ return ((S).Top==Nil)
}

void Destruct (Stack *S)
{ free (Stack);
}

void Push (Stack *S, infotype X)
{ (*S).Top++;
 (*S).T[(*S).TOP] = X;
}

void Pop (Stack *S, infotype *X)
{ *X = (*S).T[(*S).TOP];
  (*S).Top–;
}

int MakeFile (Stack S)
{ f = fopen (“file.int”, “r+”);
 ((S).Top==1);
}
    

kelima toc.c

/* file : toc*/

#include <stdlib.h>
#include <stdio.h>
#include “stack.h”

void toc ()
{ int X,
  int retval;
 
  if IsEmpty (Stack S)
    { printf (“File kosong, belum ada file yang disimpan\n”); /* jika file toc kosong*/
      MakeFile (S);
    };
  else /* is not Empty*/
    { f= fopen (“file.int”, “r+”)
      retval = fscanf (f, “%c”,  &CC);
      push (S,X); /* tambahin file ke stack*/
    };
}

tapi ini semua aku gak tau bner apa salah, tolong benerin klo ada yang salah, trus kasih saran untuk diperbaiki ya, plissss banget…..hehehe

Gisca ^^

No Comments Yet »

RSS umpan untuk komentar-komentar dalam tulisan ini. URI Lacak Balik

Tinggalkan komentar

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Blog pada WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.