Posts

Showing posts from December, 2018

Sorting & Searching

Image
Sorting: Simple sorting: Bubble sort  Membandingkan index satu per satu dengan sebelahnya dan swap dengan kondisi jika index lebih besar dari sebelahnya untuk urut berdasarkan ascending , jika lebih kecil maka descending  Selection sort Menbandingkan index dengan semua data sampai mendapat yang paling kecil atau paling besar lalu di swapkan ke depan Insertion sort Menbandingkan index dengan sebelahnya jika kondisi true maka diswap , setelah diswap maka akan di cek lagi kondisi dengan index sebelumnya sampai terurut , jika kondisi false maka akan lanjut ke index selanjutnya Intermediate sorting: Quick sort Membagi array menjadi bagian - bagian dengan cara menentukan pivot yang paling pertama atau yang paling terakhir , lalu dibagi dengan cara jika nilai lebih besar dari pivot maka akan di sub array pertama , jika nilai lebih kecil maka di sub array kedua , pada sub array sama akan diulang proses nya , sampai tidak bisa di bagi lagi , maka akan terurut ...

FILE Processing

Basics of File Handling in C So far the operations using C program are done on a prompt / terminal which are not stored anywhere. But in software industry, most of the programs are written to store the information fetched from the program. One such way is to store the fetched information in a file. Different operations that can be performed on a file are: Creation of a new file (fopen with attributes as “a” or “a+” or “w” or “w++”) Opening an existing file (fopen) Reading from file (fscanf or fgetc) Writing to a file (fprintf or fputs) Moving to a specific location in a file (fseek, rewind) Closing a file (fclose) The text in the brackets denotes the functions used for performing those operations. When working with files, you need to declare a pointer of type file. This declaration is needed for communication between the file and program. FILE *fp; Opening a file is performed using the library function in the  "stdio.h"  header file: fopen(). The...