Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions app/page_insertionSort/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ export default function Home() {
const [animSpd, setAnimSpd] = useState(1);

const codeSnippets = {
c: ``,
c: `void insertionSort(int arr[], int n) {
for (int i = 1; i < n; i++) {
int key = arr[i];
int j = i - 1;

while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j--;
}

arr[j + 1] = key;
}
}
`,
js: `function bubbleSort(arr) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u didn't change the js code

let n = arr.length;
for (let i = 0; i < n - 1; i++) {
Expand All @@ -33,11 +46,33 @@ export default function Home() {
return arr;
}
`,
py: `def greet(name):
return "Hello, " + name`,
cpp: `std::string greet(std::string name) {
return "Hello, " + name;
}`,
py: `def insertion_sort(arr):
for i in range(1, len(arr)):
key = arr[i]
j = i - 1

while j >= 0 and arr[j] > key:
arr[j + 1] = arr[j]
j -= 1

arr[j + 1] = key
`,
cpp: `void insertionSort(std::vector<int>& arr) {
int n = arr.size();

for (int i = 1; i < n; ++i) {
int key = arr[i];
int j = i - 1;

while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
--j;
}

arr[j + 1] = key;
}
}
`,
idea: `# first loop with i as element

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to change the idea part. Write what you understand

# second loop with j as element
if j>i:
Expand Down