Step by step

My diary

...

Search

breakinformation. Powered by Blogger.

Step by step

2019년 3월 29일 금요일

sort strings


123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778#include <stdio.h>#include <stdlib.h> int String_Compare(const char* _First_String_, const char* _Second_String_);char* String_Copy(char* destination, const char* source); void Bubble_Sort(char array[][10], int size);void swap(char array[][10], int Partial_Element); void display(char array[][10], int size); int main(void) {     char _String[10][10] = { "apple", "banana", "orange", "pineapple", "melon", "mango", "papaya", "fig", "coconut", "pear" };     display(_String, 10);     printf("\n\n== bubble sort ==\n");    Bubble_Sort(_String, 10);    display(_String, 10);     return 0;} void display(char array[][10], int size) {     int index = 0;    for (index = 0; index < size; index++) {         printf("%s\n", *(array + index));    }     return;} void Bubble_Sort(char array[][10], int size) {     int All_Element = 0, Partial_Element = 0;    for (All_Element = 0; All_Element < size; All_Element++) {        for (Partial_Element = 0; Partial_Element < size - 1; Partial_Element++) {            if (String_Compare(*(array + Partial_Element + 0), *(array + Partial_Element + 1)) > 0) {                 swap(array, Partial_Element);            }        }        Partial_Element++;    }    return;} void swap(char array[][10], int Partial_Element) {     char* temporary = (char*)calloc(100, sizeof(char));    String_Copy(temporary, *(array + Partial_Element + 0));    String_Copy(*(array + Partial_Element + 0), *(array + Partial_Element + 1));    String_Copy(*(array + Partial_Element + 1), temporary);     return;} char* String_Copy(char* destination, const char* source) {     char* Return_Result = destination;    while (*destination++ = *source++);    return (char*)Return_Result;} int String_Compare(const char* _First_String_, const char* _Second_String_) {     int result = 0;    while (!(result = *(unsigned char*)_First_String_ - *(unsigned char*)_Second_String_) && *_Second_String_)        ++_First_String_, ++_Second_String_;     if (result < 0) return -1;    else if (result > 0) return 1;    return 0;} Colored...

2019년 3월 28일 목요일

Array list


"arraylist.h" 12345678910111213141516171819202122232425262728293031323334#ifndef _ARRAY_LIST_#define _ARRAY_LIST_ struct Array_List_Node_Type {     int data;}; struct Array_List_Type {     int Maximum_Element_Count;    int Current_Element_Count;    struct Array_List_Node_Type* Pointer_Element;}; struct Array_List_Type* Create_Array_List(int Maximum_Element_Count);void Delete_Array_List(struct Array_List_Type* Pointer_List);int Is_Array_List_Full(struct Array_List_Type* Pointer_List);int Add_Array_List_Element(struct Array_List_Type* Pointer_List, int position, struct Array_List_Node_Type element);int Remove_Array_List_Element(struct Array_List_Type* Pointer_List, int position);struct Array_List_Node_Type* Get_Array_List_Element(struct Array_List_Type* Pointer_List, int position);void Display_Array_List(struct Array_List_Type* Pointer_List);int Get_Array_List_Length(struct Array_List_Type* Pointer_List); #endif // !_ARRAY_LIST_ #ifndef _COMMON_LIST_DEFAULT_#define _COMMON_LIST_DEFAULT_ #define TRUE    1#define FALSE    0 #endif // !_COMMON_LIST_DEFAULT_ Colored...