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

Headers for the file that contains array management routines (Insertion Sort) More...

Go to the source code of this file.

Functions

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

Detailed Description

Headers for the file that 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
67{
68 //
69 // check if index is valid
70 //
71 if (Index >= *NumberOfItems)
72 {
73 return FALSE;
74 }
75
76 for (size_t i = Index + 1; i < *NumberOfItems; i++)
77 {
78 ArrayPtr[i - 1] = ArrayPtr[i];
79 }
80
81 (*NumberOfItems)--;
82
83 return TRUE;
84}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54

◆ InsertionSortInsertItem()

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

Function to implement insertion sort.

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