示例#1
0
文件: adttabel.c 项目: rivasyafri/ADT
ElType ValMin (TabInt T) {
	/*	Kamus */
	ElType a=GetElmt(T,GetFirstIdx(T));
	IdxType i=GetFirstIdx(T)+1;
	/*	Algoritma */
	while (i<=GetLastIdx(T)) {
		if (a>GetElmt(T,i)) {
			a=GetElmt(T,i);
		}
		i++;
	}
	return a;
}
示例#2
0
文件: adttabel.c 项目: rivasyafri/ADT
/*	Selektor Set */
void SetTab (TabInt Tin, TabInt *Tout) {
	/*	Kamus */
	int i=GetFirstIdx(Tin);
	/*	Algoritma */
	MakeEmpty(MaxNbEl(Tin),Tout);
	while (i<=GetLastIdx(Tin)) {
		SetEl(Tout,i,GetElmt(Tin,i));
		i++;
	}
}
示例#3
0
/*
nama :dyarsa S.Pamungkas
Nim  :A11.2011.06186
Klmpk: A11.4204


---copyright dy_arsa---
*/
int main()
{
TabInt T,T1,T2,TCopy,TInv,TSim,TBaca;
 int i;
    MakeEmpty(&T1);
    for (i=1;i<=10;i++)
    {

        T1.TI[i]=i;
    }
     TulisIsiTab(T1);
//       printf("Tekan sembarang tombol untuk melanjutkan....\n");getch();
    printf("\n");
    printf("Empty T=1, F=0 :%d\n",IsEmpty(T1));
    printf("Full   T=1, F=0 :%d\n",IsFull(T1));
//       printf("Tekan sembarang tombol untuk melanjutkan....\n");getch();
    printf("\n");
    printf("index 0           :%s\n",IsIdxValid(T1,0)?"Ya":"Tidak");
    printf("index 1           :%s\n",IsIdxValid(T1,1)?"Ya":"Tidak");
    printf("index 5           :%s\n",IsIdxValid(T1,5)?"Ya":"Tidak");
    printf("index 10          :%s\n",IsIdxValid(T1,10)?"Ya":"Tidak");
    printf("index 101         :%s\n",IsIdxValid(T1,101)?"Ya":"Tidak");

    printf("GetFirstIdx Efektif]  :%d\n",GetFirstIdx(T1));
    printf("GetLastIdx Efektif   :%d\n",GetLastEfIdx(T1));
    printf("\n");
    MakeEmpty(&T2);
    for (i=1;i<=10;i++)
    {

        T2.TI[i]=i*2+1;
    }
    printf("T1\n");
    TulisIsiTab(T1);
    printf("\nT2 \n");
    TulisIsiTab(T2);
    printf("\n");
    printf("\nT1+T2 :\n"); PlusTab(T1,T2);
    printf("\nT2-T1 :\n"); MinusTab(T2,T1);
    printf("\nT1*T2 :\n");KaliTab(T1,T2);
    printf("\nT1*2:\n"); KaliKons(T1,2);
    printf("\nApakah T1 Sama dg T2?: %s\n",IsEQ(T1,T2)?"Ya":"Tidak");
    printf("\nApakah T1 Kurang dari T2?: %s\n",IsLess(T1,T2)?"Ya":"Tidak");

    printf("\nApa Nilai Maksimum tabel T1?: %i\n",ValMax(T1));
    printf("\nApa Nilai Minimum tabel T1?: %i\n",ValMin(T1));
    printf("\nApa index Nilai Maksimum tabel T2?: %i\n",IdxMaxTab(T2));
    printf("\nApa index Nilai Minimum tabel T2?: %i\n",IdxMinTab(T2));
    printf("\nApa Nilai Maksimum tabel T?: %i\n",Max(T));
    printf("\nApa Nilai Minimum tabel T?: %i\n",Min(T));
    printf("\nApa Nilai MaksMin tabel T?: ");MaxMin(T);

    return 0;
}
示例#4
0
文件: adttabel.c 项目: rivasyafri/ADT
void TulisIsi (TabInt T) {
	/*	Kamus */
	IdxType i=GetFirstIdx(T);
	/*	Algoritma */
	if (IsEmpty(T)) {
		printf("Tabel kosong\n");
	} else {
		while (i<=GetLastIdx(T)) {
			printf("%d.	%d\n",i,GetElmt(T,i));
			i++;
		}
	}
}
示例#5
0
文件: adttabel.c 项目: rivasyafri/ADT
/*	Tabel boleh kosong */
IdxType Search1 (TabInt T, ElType X) {
	/*	Kamus */
	IdxType i;
	/*	Algoritma */
	if ((NbElmt(T)==0)||(!SearchB(T,X))) {
		return IdxUndef;
	} else {
		i=GetFirstIdx(T);
		while ((i<=GetLastIdx(T))&&(GetElmt(T,i)!=X)) {
			i++;
		}
		return i;
	}
}
示例#6
0
文件: adttabel.c 项目: rivasyafri/ADT
TabInt InverseTab (TabInt T) {
	/*	Kamus */
	TabInt T1;
	IdxType i=GetFirstIdx(T);
	/*	Algoritma */
	if (IsEmpty(T)) {
		return T;
	} else {
		MakeEmpty(MaxNbEl(T),&T1);
		while (i<=GetLastIdx(T)) {
			SetEl(&T1,GetLastIdx(T)-i+1,GetElmt(T,i));
			i++;
		}
		return T1;
	}
}
示例#7
0
文件: adttabel.c 项目: rivasyafri/ADT
boolean SearchB (TabInt T, ElType X) {
	/*	Kamus */
	IdxType i;
	boolean Found=false;
	/*	Algoritma */
	if (NbElmt(T)!=0) {
		i=GetFirstIdx(T);
		while (i<=GetLastIdx(T)) {
			if (GetElmt(T,i)==X) {
				Found=true;
			}
			i++;
		}
	}
	return Found;
}
示例#8
0
文件: adttabel.c 项目: rivasyafri/ADT
boolean IsLess (TabInt T1, TabInt T2) {
	/*	Kamus */
	boolean a=true;
	IdxType i=GetFirstIdx(T1),j;
	/*	Algoritma */
	if (NbElmt(T1)<=NbElmt(T2)) {
		j=GetLastIdx(T1);
	} else {
		j=GetLastIdx(T2);
	}
	while ((i<=j)&&(a)) {
		if (GetElmt(T1,i)>GetElmt(T2,i)) {
			a=false;
		}
		i++;
	}
	return a;
}
示例#9
0
文件: adttabel.c 项目: rivasyafri/ADT
/*	Operasi pembandingan tabel : < =, > */
boolean IsEQ (TabInt T1, TabInt T2) {
	/*	Kamus */
	boolean a=true;
	IdxType i=GetFirstIdx(T1);
	/*	Algoritma */
	if ((MaxNbEl(T1)!=MaxNbEl(T2))&&(NbElmt(T1)!=NbElmt(T2))) {
		a=false;
	} else {
		while (i<=GetLastIdx(T1)) {
			if ((T1).TI[i]!=(T2).TI[i]) {
				/* 	Tidak menggunakan GetElmt karena masukan i tidak berada 
					di antara FirstIdx..LastIdx melainkan bisa diluar itu */
				a=false;
			}
			i++;
		}
	}
	return a;
}
示例#10
0
文件: adttabel.c 项目: rivasyafri/ADT
void TulisIsiTab (TabInt T) {
	/*	Kamus */
	int j=NbElmt(T);
	IdxType i=GetFirstIdx(T);
	/*	Algoritma */
	if (j==0) {
		printf("[]");
	} else {
		printf("[");
		while (i<=GetLastIdx(T)&&(j>=1)) {
			printf("%d",GetElmt(T,i));
			if (j>1) {
				printf(", ");
			}
			j--;
			i++;
		}
		printf("]\n");
	}
}
示例#11
0
文件: adttabel.c 项目: rivasyafri/ADT
/*	--- SORTING --- */
void MaxSortDesc (TabInt *T) {
	/*	Kamus */
	IdxType i,j,imaks;
	ElType Temp;
	/*	Algoritma */
	if (!IsEmpty(*T)) {
		i=GetFirstIdx(*T);
		while (i<GetLastIdx(*T)) {
			imaks=i;
			j=i+1;
			while (j<=GetLastIdx(*T)) {
				if (GetElmt(*T,imaks)<GetElmt(*T,j)) {
					imaks=j;
				}
				j++;
			}
			Temp = GetElmt(*T,i);
			SetEl(T,i,GetElmt(*T,imaks));
			SetEl(T,imaks,Temp);
			i++;
		}
	}
}
示例#12
0
文件: adttabel.c 项目: rivasyafri/ADT
IdxType Search2 (TabInt T, ElType X) {
	/*	Kamus */
	boolean Found=false;
	IdxType i;
	/*	Algoritma */
	if (NbElmt(T)==0) {
		return IdxUndef;
	} else {
		i=GetFirstIdx(T);
		while ((i<=GetLastIdx(T))&&(!Found)) {
			if (GetElmt(T,i)==X) {
				Found=true;
			} else {
				i++;
			}
		}
		if (Found) {
			return i;
		} else {
			return IdxUndef;
		}
	}
}
示例#13
0
文件: adttabel.c 项目: rivasyafri/ADT
void Add1Urut (TabInt *T, ElType X) {
	/*	Kamus */
	IdxType i,j;
	boolean pas=false;
	/*	Algoritma */
	if (IsEmpty(*T)) {
		SetEl(T,1,X);
	} else if (!IsFull(*T)) {
		i=GetFirstIdx(*T);
		j=GetLastIdx(*T);
		if (NbElmt(*T)!=1) {
			while ((i<=j)&&(!pas)) {
				if (GetElmt(*T,i)>=X) {
					pas=true;
				} else {
					i++;
				}
			}
			while (j>=i) {
				if (j>i) {
					SetEl(T,j+1,GetElmt(*T,j));
				} else {
					SetEl(T,j+1,GetElmt(*T,j));
					SetEl(T,j,X);
				}
				j--;
			}
		} else {
			if (GetElmt(*T,i)<=X) {
				SetEl(T,i+1,GetElmt(*T,i));
				SetEl(T,i,X);
			} else {
				SetEl(T,i+1,X);
			}
		}
	}
}
示例#14
0
文件: adttabel.c 项目: rivasyafri/ADT
void InsSortAsc (TabInt *T) {
	/*	Kamus */
	IdxType i,j;
	ElType Temp;
	/*	Algoritma */
	if (!IsEmpty(*T)) {
		i=GetFirstIdx(*T)+1;
		while (i<=GetLastIdx(*T)) {
			Temp=GetElmt(*T,i);
			j=i-1;
			while ((Temp<GetElmt(*T,j))&&(j>1)) {
				SetEl(T,j+1,GetElmt(*T,j));
				j--;
			}
			if (Temp>=GetElmt(*T,j)) {
				SetEl(T,j+1,Temp);
			} else if (Temp<GetElmt(*T,j)) {
				SetEl(T,j+1,GetElmt(*T,j));
				SetEl(T,j,Temp);
			}
			i++;
		}
	}
}
示例#15
0
文件: adttabel.c 项目: rivasyafri/ADT
ElType Min (TabInt T) {
	return GetElmt(T,GetFirstIdx(T));
}
示例#16
0
文件: adttabel.c 项目: rivasyafri/ADT
boolean IsIdxEff (TabInt T, IdxType i) {
	return (i>=GetFirstIdx(T))&&(i<=GetLastIdx(T));
}