HyperDbg Debugger
Loading...
Searching...
No Matches
InsertionSort.c File Reference

The file contains array management routines (Insertion Sort). More...

#include "pch.h"

Functions

BOOLEAN InsertionSortInsertItem (UINT64 ArrayPtr[], UINT32 *NumberOfItems, UINT32 MaxNumOfItems, UINT32 *Index, UINT64 Key)
 Function to implement insertion sort.
BOOLEAN InsertionSortDeleteItem (UINT64 ArrayPtr[], UINT32 *NumberOfItems, UINT32 Index)
 Function to implement insertion sort.

Detailed Description

The file contains array management routines (Insertion Sort).

Author
Mohammad K. Fallah (mkf19.nosp@m.80@g.nosp@m.mail..nosp@m.com)
Version
0.6
Date
2023-08-21

Function Documentation

◆ InsertionSortDeleteItem()

BOOLEAN InsertionSortDeleteItem ( UINT64 ArrayPtr[],
UINT32 * NumberOfItems,
UINT32 Index )

Function to implement insertion sort.

Parameters
ArrayPtr
NumberOfItems
Index
Returns
BOOLEAN
70{
71 //
72 // check if index is valid
73 //
74 if (Index >= *NumberOfItems)
75 {
76 return FALSE;
77 }
78
79 for (SIZE_T i = Index + 1; i < *NumberOfItems; i++)
80 {
81 ArrayPtr[i - 1] = ArrayPtr[i];
82 }
83
84 (*NumberOfItems)--;
85
86 return TRUE;
87}
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113

◆ InsertionSortInsertItem()

BOOLEAN InsertionSortInsertItem ( UINT64 ArrayPtr[],
UINT32 * NumberOfItems,
UINT32 MaxNumOfItems,
UINT32 * Index,
UINT64 Key )

Function to implement insertion sort.

Parameters
ArrayPtr
NumberOfItems
MaxNumOfItems
Index
Key
Returns
BOOLEAN
27{
28 UINT32 Idx;
29
30 if (*NumberOfItems >= MaxNumOfItems)
31 {
32 //
33 // Array list is full
34 //
35 return FALSE;
36 }
37
38 Idx = *NumberOfItems;
39
40 //
41 // Move elements of Arr[0..i-1], that are greater than Key,
42 // to one position ahead of their current position
43 //
44 while (Idx > 0 && ArrayPtr[Idx - 1] > Key)
45 {
46 ArrayPtr[Idx] = ArrayPtr[Idx - 1];
47 Idx = Idx - 1;
48 }
49 ArrayPtr[Idx] = Key;
50 *Index = Idx;
51 (*NumberOfItems)++;
52
53 //
54 // Successfully inserted
55 //
56 return TRUE;
57}
unsigned int UINT32
Definition BasicTypes.h:54