Hey everyone, So, I need help understanding why I'm not able sort my code: here is my code (so far) for my selection sort. I have only written the iterative form of Selection Sort, but I know how to do it recursively as well (which is required for my homework). When I print it out, it just prints out the unsorted array AFTER I call the selection sort. Here is my full code so far: main.cpp #include <iostream> #include <vector> #include <cstdlib> #include <ctime> #include "SelectionSort.h" using namespace std; template <class print> void printData(print a, int sizeOf); template <class randomData> …

Member Avatar
Member Avatar
+0 forum 1

I have put together some code for a homework assignment and I have almost got it working. There are a few key items that are missing or not fully functional and I am fresh out of ideas on how to attack it. The code is to take 9 digits/integers from a user's input and through a "selection sort" put them in order from least to greatest. I am also supposed to show the array for each step the code takes (each time a number moves). [CODE] /*%%%%%%%%%%%%%%%%%%%%%% Selection Sort Algorithm %%%%%%%%%%%%%%%%%%%%%%*/ #include <iostream> #include <iomanip> #include <sstream> #include <cmath> #include …

Member Avatar
Member Avatar
+0 forum 2

Hello, I wrote two programs which sort first names which are already sorted by their last names.One is with Selection sort and the other is with Quicksort! The question is , "is any one of them stable?." "If the names with same first names are still in sorted order by their last names, we call that sort a stable sort" I got in-stable results for both the sorts by the programs i wrote.Am I correct? Or is any thing wrong with my codes? I'm a newbie please help me somebody... Quicksort [CODE]//by ABVK #include<stdio.h> #include<string.h> #include<stdlib.h> int quick(char fname[][10],char lname[][10],int …

Member Avatar
Member Avatar
+0 forum 5

Hi, I am tasked with writing selection sort in assembly. We are writing for the ARM processor. Currently, this is what I have: [CODE] sort2: 73 stmdb sp!, {v1-v5, lr} @ Copy registers to stack 74 ldrb r5, [a2] @ J = n 75 76 ldrb v2, [a1] 77 cmp a2, #1 78 beq skip_sorting 79 80 sub r5, r5, #1 @ j = N-1 81 outer_loop: 82 cmp r5, #0 @ j > 0 add j-- at the bottom 83 beq skip_sorting 84 85 inner_loop: 86 mov r6, r5 @ k = j 87 sub r6, r6, #1 @ …

Member Avatar
+0 forum 0

I am implementing Selection sort in doubly - linked list. I have to sort list by surnames by finding smallest element and inserting it into beginning of the list But there are some troubles when I run my program I have NIL exception in Sort Method in while loop. Help will be appreciated. Thanks. It's whole app so you can compile it and run. [CODE]public class LinkedList { public Node first; public Node last; public LinkedList() { first = null; last = null; } public void addFirst(Student student) { Node f = first; Node newNode = new Node(student); first = …

Member Avatar
Member Avatar
+0 forum 2

This is suppose to be a simple selection sort but I think I'm missing something because my output isn't completed sorted right. [CODE]void SelectionSort(data list[], int length) { int index; int smallestIndex; int minIndex; data temp; for( index = 0; index < length; index++) { smallestIndex = index; for(minIndex = index + 1; minIndex < length; minIndex++) { if( list[minIndex].stateCity < list[smallestIndex].stateCity) { smallestIndex = minIndex; temp = list[smallestIndex]; list [smallestIndex] = list[index]; list[index] = temp; } // end if } // end for loop with minIndex } // end for loop index } // end function SelectionSort[/CODE] output is …

Member Avatar
Member Avatar
+0 forum 3

The End.