GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PLM-PLD_ClassWorks/PLD_InsertionSort_stepByStep.cpp at main · proDev-Theron/PLM-PLD_ClassWorks

Expand file tree

/

PLD_InsertionSort_stepByStep.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
59 lines (52 loc) · 1.52 KB
/

PLD_InsertionSort_stepByStep.cpp

Copy path

File metadata and controls

59 lines (52 loc) · 1.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
/*
Created by Theron Adrianne Bueno
January 23, 2021
Subject: Programming Logic and Design (CPE 0112.1) - Pamantasan ng Lungsod ng Maynila (PLM)
Task: Demonstrate Insertion Sort
*/
using namespace std;
//fuction declaration
template <class elemType>
void insertionSort(elemType list[], int length);
template <class elemType>
void print(elemType list[], int length);
//initialize array
int intList[] = {64, 19, 45, 88, 12,55, 23, 67, 89, 90, 11, 56};
int sukat = sizeof(intList)/sizeof(intList[0]); //get array size
int main()
{
cout << "Before sorting, intList: ";
print(intList, sukat);
cout << endl;
insertionSort(intList, sukat);
return 0;
}
template <class elemType>
void insertionSort(elemType list[], int length)
{
for (int firstOutOfOrder = 1; firstOutOfOrder < length;
firstOutOfOrder++)
if (list[firstOutOfOrder] < list[firstOutOfOrder - 1])
{
elemType temp = list[firstOutOfOrder];
int location = firstOutOfOrder;
do
{
list[location] = list[location - 1];
location--;
}
while (location > 0 && list[location - 1] > temp);
list[location] = temp;
;
print(intList, sukat);//print line by line process of swapping elements
}
cout << endl;
} //end insertionSort
template <class elemType>
void print(elemType list[], int length)
{
for (int i = 0; i < length; i++)
cout << list[i] << " ";
cout << endl;
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.