algo n prog
1. pointer and array
- pointer definition
- pointer to pointer
- array
- pointer definition
pointer is a variable that store address of another variable
- pointer to pointer
pointer to pointer is a variable that saves another address of a pointer
- array
2. function and recrusion
- modular programing
- function
- indentifier scoping
- recursion definition
- recursive function
- modular programing
the advantages of using modules is make a problem easier, can be done by many progamer
easier to debug
- function
function in c usually written above the inisiator
- identifier scoping
there is 2 identifier, local and global
1. local
local variable is a variable that you put inside function
2. global
global variable is a variable that you put outside function so every function can read the variable
- recursive definition
recursive is a function call inside a function
3. structure and unions & memory allocation
- structures
- union
- memory allocation
- structure
structure is a data type that used to store a group of data with various of data type
-union
union is used to combie a memory, by. using union, a memory location can be assingn for two or mre variable with different data type
-memory allocation
memory allocation is acquiring some memory space manage by the os to be used by a program
-union
union is used to combie a memory, by. using union, a memory location can be assingn for two or mre variable with different data type
-memory allocation
memory allocation is acquiring some memory space manage by the os to be used by a program
4. file processing
- open file
- close file
- input and output file
- open file
to open file use "FILE *fopen (const char *filename, const char *mode);"
mode : (r,w,a,rb,wb)
- close file
to close file use "int fclose (FILE *stream);"
- input and output file
fgetc = input
"int fgetc(FILE*stream);"
read one character
fputc = output
"int fputc(int c, FILE*steam);"
write one character
fgets = input
"char*fgets(char*string, int n, FILE *stream);"
read one line that end with "\n"
fputs = output
"int fputs(const char*string,FILE*stream);"
write a line
fscanf = input
"int fscanf(FILE*stream, const char*format[,argument]...);"
read data from file inline with the scanf formating
fprintf = output
"inr fprintf(FILE*stream, cont char*format[,argument]...);"
write a dara to file using the printf format
fwrite
"size_tfwrite(const void*buffer, size_t size,size_t count, FILE*stream);"
write a block of data in the buffer area to the file
fread
"size_t fread(void*buffer,size_t size,size_t count, FILE *stream)"
read a block size of data from a file
feof
"int feof(FILE*stream)"
finding out if pointer has reached end-of-file
5. sorting and searching
- bubble sort
- selection sort
- insertion sort
- quick sort
- merge sort
- linear search
- binary search
- interpolation search
- sort
sort is a action to place something in order
- bubble sort
voidBubble(int *DataArr, int n)
{
int i, j;
for(i=1; i<n; i++)
for(j=n-1;j>=i;j--)
if(DataArr[j-1] > DataArr[j])
Swap(&DataArr[j-1],&DataArr[j]);
}
- selection sort
for(i=0; i<N-1; i++{ /* N=number of data */
Set idx_smallestequal to i
for(j=i+1; j<N; j++){
If array[ j ] < array [ idx_smallest] then idx_smallest= j
}
Swap array[ i] with array[ idx_smallest]
}
- insertion sort
for(i=1; i<n; i++) {
x = A[i], insert x to its suitable place between A[0] and A[i-1].
}
- quick sort
voidQuickSort(int left, intright)
{
if(left< right){
//arrangeelements R[left],...,R[right] that
//producingnewsequence:
R[left],...,R[J-1] < R[J] andR[J+1],...,R[right] > R[J].
QuickSort(left, J-1);
QuickSort(J+1,right);
}
}
- merge sort
- searching
searching is an action to find something
- linear search
•Algorithm:
1. n: total recordofarrayx.
2. For eachx[i], 0 £ i £n-1,checkwhetherx[i] = key.
3. If x[i] = key, thenthesearcheddataisfoundin index=i. Finished.
4. If x[i]¹key, thencontinuesearchinguntil thelastdatawhichisi = n-1.
5. Ifi= n-1 andx[i] ¹key, itmeansthedataisnot existin thelist, andsetindex= -1. Finished
- binary search
- interpolation search

No comments:
Post a Comment