##vbScript - Sorting With and Without Code Please see my post [vbScript - The Basics](https://www.daniweb.com/programming/threads/516400/vbscript-the-basics) for more details on vbScript. Sorting is something that must be done from time to time. I'm going to examine three ways. The first is the well known (at least by name) QuickSort method. Rather than repeating existing explanations of the actual algorithm I'll just refer you to the [Wikipedia QuickSort article](https://en.wikipedia.org/wiki/Quicksort) and present the code with comments below. The second method uses a binary tree. The concept is simple even if the implementation is a little difficult to grasp initially. We start with the …

Member Avatar
+1 forum 0

hello, i just set goal of mastering algorith and i just get started i have an algorhtm for insert sort and i when i write it in c it is not sorting this is the algorith for j D 2 to A_length key = A[j] // Insert A[j] into the sorted sequence A[1..j-1] i = j-1 while i > 0 and A[i] > key A[i+1] = A[i] i = i-1 end while A[i+1]= key end for and here is the c code #include <stdio.h> #define LENGHT 6 int main(void){ int j,i, key; int arr[LENGHT]; for(j=0; j < LENGHT; j++){ printf("enter …

Member Avatar
Member Avatar
+0 forum 4

http://imgur.com/gallery/dYgFh has a gallery of some visualizations of classic sorting. For your enjoyment. And with sound too! https://www.youtube.com/watch?v=kPRA0W1kECg This post is strictly for programming's secret pleasures.

Member Avatar
+2 forum 0

I have to sort the 5 elements in a, the Days and the Vowels. How do I use the template <class T> with the way I put this?? #include <iostream> #include <algorithm> #include <iomanip> using namespace std; // Function prototypes void DisplayA(int[], int); void showArray(int[], int); void DisplayB(string[], int); void showArrayDays(string[], int); int main() { int a[5] = { 10, 4, 9, 55, 11 }; string Days[7] = { "Mon", "Tue", "Wed", "Thr", "Fri", "Sat", "Sun" }; char Vowels[5] = { 'U', 'O', 'I', 'E', 'A' }; cout << "Original array\n"; cout << "a: "; showArray(a, 5); cout << "Days: …

Member Avatar
Member Avatar
+0 forum 3

I am trying to sort averages of scores in a class by pupil, from highest to lowest. My data is stored in text files like this: Charlie:0 Seema:2 Amber:4 Paige:5 Amber:8 Keith:1 Charlie:8 Seema:0 Charlie:9 Seema:3 Paige:0 Paige:4 Paige:4 Charlie:1 Keith:5 Keith:3 Here is my code so far: with open("class {0}.txt".format(Class)) as f: d = {} #loop to split the data in the text file for line in f: column = line.split(":") #identifies the key and value with either 0 or 1 names = column[0][Click Here](null) scores = int(column[1].strip()) #appends values if a key already exists tries = 0 while …

Member Avatar
Member Avatar
+0 forum 5

[QUOTE]Assume you have a int variable n that has already been declared and initialized. Its value is the number of integers that need to be read in from standard input and printed out in sorted (ascending) order, each on a line by itself. Furthermore, there are no duplicates in the input and every number to be read is a non-negative value that is less than n's value. In this exercise you may not use any array (or fancy STL collection such as a vector). You may declare a variable or two as needed. With these restrictions, read the n values …

Member Avatar
Member Avatar
+0 forum 23

I have the following struct definition: struct finfo { string filename; long fsize; bool operator() (finfo i, finfo j){return (i.fsize > j.fsize);} } fstruct; And the following vector definition: vector<finfo> fdata; In the code I use the following statement to sort the vector elements by fsize: sort(fdata.begin(),fdata.end(),fstruct); This works perfectly well, but how can I sort by the field "filename" when i.fsize = j.fsize ? (The vector is filled by reading directory information, and putting the filenames and filesizes in the appropriate fields in the struct. If the filesize is equal I want to sort the files alphabetically by file …

Member Avatar
Member Avatar
+0 forum 3

I'm new at C++ ..and I dont know what should I do whith my program ... this program's input for exg. is: 5 mary sara kimi lili olive : : and then sorting them .. but my problem is that when I submit my home work they score me "0" and Icant find out why..! #include <iostream> #include <string.h> #define MAXNAMES 100 using namespace std; int compare(string s1, string s2){ int i; for ( i = 0; s1[i] && s2[i]; ++i) { /* If characters are same or inverting the 6th bit makes them same */ if (s1[i] == s2[i] …

Member Avatar
Member Avatar
+0 forum 2

I want to write a code for Radix Sort based in this way how I made the Quick Sort, how can I do with Radix Sort, can anybady have any idea I have search a lot but I can not find any exactly what I need #include <iostream> #include <conio.h> #include <time.h> #include <stdlib.h> //srand and rand functions using namespace std; void add_random_numbers(long arr[], long b); void QuickSort(long vektori[], long left, long right); long const MADH_MAX_VEKTORIT = 110000; int main() { long random_vector[MADH_MAX_VEKTORIT]; long vector[] = { 1000, 10000, 15000, 25000, 30000, 45000, 50000, 60000, 75000, 90000, 100000 }; long …

Member Avatar
Member Avatar
+0 forum 1

I want to make this code with random numebr array and time executation? Does anybady nows how can I do? #include <iostream> using namespace std; void print(int a[], int sz) { for (int i = 0; i < sz; i++ ) cout << a[i] << " "; cout << endl; } void CountingSort(int arr[], int sz) { int i, j, k; int idx = 0; int min, max; min = max = arr[0]; for(i = 1; i < sz; i++) { min = (arr[i] < min) ? arr[i] : min; max = (arr[i] > max) ? arr[i] : max; } …

Member Avatar
Member Avatar
+0 forum 1

I have been beating my head into the desk with this issue, and I don't think it's a simple 'uniq' or 'sort' issue. I have a file, with many duplicate values in them. File ---------- dog dog cat owl owl turkey weasel giraffe giraffe rooster The output I am looking for would only have the following from the above file: Output: ---------- cat turkey weasel rooster Everything I've found so far either removes all the dupes, and keeping one copy of 'owl' or 'dog', which is not what I need. If it's duplicated, I don't want it at all in …

Member Avatar
Member Avatar
+0 forum 4

Earlier I raised a question in this forum regarding the sorting of database and Reverend Jim answered me as follows. It was Ok SELECT * FROM mytable ORDER BY fieldname But then I faced another problem As I mentioned in that I wanted to sort ORDER by 'Tdate' which is a field in my table. It is the transaction date.Worked well, sorted datewise.But the problem is when there are many transactions in the same date,they are not sorted transaction wise,ie.first transaction First,last transaction at the bottom(though Datewise it is perfect).This will affect the calculation.The last transaction is depending on the …

Member Avatar
Member Avatar
+0 forum 1

Hi evryone! :) I'm a complete beginner in Java and today i'm found my self stack while trying to solve a problem. Basically what i have to do is to write a program that sorts three integers. The integers are entered from the input dialogs and stored in variables num1, num2, and num3, respectively. The program sorts the numbers so that num1 <= num2 <= num3. I tryed everything i can, but at the end still can't get the jobe done. PLEASE HELP!!! :'( Muchas Gracias in advance!!! :)

Member Avatar
Member Avatar
-1 forum 9

Friends I met with a problem...Please help I have a table 'Tran' in Access Database which has several fields of which one is 'Date' I added several records through programm on different dates.Everything OK. All the records appeared in a chronological way ie.Earlier to Later order . Later I deleted some earlier records randomly.(Not through programm but manually).Now when I try to add record through programm the 'Date' order is not retained. I think the new added record takes the place of the deleted record.It will affect the output of the programme.Is there any way to maintain the chronological order …

Member Avatar
Member Avatar
+0 forum 2

/* * File: main.cpp * Author: TBuchli * * Write a program that helps a real estate agent calculate an average price of *up to 20 homes. An array of data type double should be used to contain the *prices. The program should prompt the user to enter the number of prices to *average — a maximum of 20 prices. * * Then, the program should prompt the user to enter each price. Once all of the *prices have been entered into the array, sort them in ascending order. The *output should include a listing of the prices entered, and …

Member Avatar
Member Avatar
+0 forum 4

#include<fstream.h> #include<conio.h> #include<string.h> #include<stdio.h> void main() { clrscr(); ofstream fout("a"); fout<<5<<"\n"<<3<<"\n"<<2<<"\n"<<4<<"\n"<<1; fout.close(); ifstream fin("a"); int i,j,k,l=0,m,n,o; while(fin) { fin>>i; l++; } l--; fin.close(); fstream fin1("a",ios::ate,ios::in); fin1.seekg(0); for(i=0;i<l-1;i++) { for(j=0;j<l-i-1;j++) { o=fin.tellg(); fin1>>m; fin1>>n; if(m>n) { fin1.seekg(o); fin1<<n; fin1<<m; fin1.seekg(o+1); } } } } //file sorting is not working if anyone can help..

Member Avatar
Member Avatar
+0 forum 3

Currently I am designing a inventory system, however jumping straight into vb.net was easier said than done. At the moment, all the information stored goes to two places, one being a master file that has all the information ever inputted, and the other being an individual file that is created and named based on the Tag number assigned. The current input fields are: 1. Tag Number 2. Data Installed 3. Location/Office 4. Type(Computer base unit, monitor, desk, file cabinet, ect) 5. Notes 6. Name of Owner Once inputed the tag number (####.txt) is saved as an independent file with the …

Member Avatar
Member Avatar
+0 forum 11

I am trying to modify my shell sort algorithm to use Hibbard's increments rather than n/2. I know that Hibbard's increments are 2k - 1, but I can't figure out how to incorporate that into my algorithm. Any suggestions to help me move forward with this? I feel like I just can't figure this one out. Here's the working version of what I have now, which is NOT using Hibbard's increments: [CODE] public void shellSort(int[] array, int lowindex, int highindex, boolean reversed) { int n = highindex - lowindex; int increment; int offset; for (increment = n / 2; increment …

Member Avatar
Member Avatar
+0 forum 4

Hello, I am very familiar with most of the sorting algorithms that are taught in first year university (as I just finished my first year in software engineering at the University of Waterloo). As such my current go-to sorting algorithms are insertion (on mostly pre-sorted data, or data where I get each element one at a time [like inputs from stdin]), merge (which I use for optimality), and heap (which I don't use too much because I happen to prefer merge :) ). Anyways, I hate writing code that is not optimal. That is why for example when I am …

Member Avatar
+0 forum 0

I have these sorting algorithms in my application, and I want to keep track the affected values, or the values that swapped during the sorting process. I want to highlight them. I have solved this issue for bubble sort and selection sort, but somehow I can't get it work with Insertion sort and shell sort. Here is the fiddle of what I am trying to do: http://jsfiddle.net/4jnXf/1/ As you can see, on the last part of the iteration, which is more likely like insertion sort, so I won't ask how to do it in insertion sort. The big problem is …

Member Avatar
Member Avatar
+0 forum 2

My Program contains 4 arrays and I want to sort the array in such a way that if one array is sorted the other array should follow it Example: unsorted array name code salary date John 52 6500 15 Suzzy 10 1500 20 Mike 20 1451 16 Sorted array(according to date) name code salary date Suzzy 10 1500 20 Mike 20 1451 16 John 10 6500 15 How can I do this type of sorting....? #include<stdio.h> #include<conio.h> struct employ { char name[20]; int code; int salary; int date; }; void main() { int i; struct employ e[5]; printf("Enter Details\n"); printf("As …

Member Avatar
Member Avatar
+0 forum 9

Hi Any idea how to solve an old exercice? The linux command ls -alR produce informations about files contained in the current directory and its subdirectories. You can save its output by using redirections (in the file output in the following example): ls -alr > output The exercice is to write a perl which take as input a file generated by the previous command and displays: 1. The sorted list of all owners (without duplicates) according their name 2. A sorted list of all filenames for which several files exists with the same filename (you should display the number of …

Member Avatar
Member Avatar
+0 forum 1

Hello, What is the best way to count the number of swaps required to sort an array that is sorted using the Quicksort algorithm? I put a counter in what I believe is in the correct position and the tests that I have run seem to be correct however Quicksort is so complex I do not trust my data. Thanks, /** The IntQuickSorter class provides a public static method for performing a QuickSort on an int array. */ public class IntQuickSorter2 { private static int track = 0; /** The quickSort method calls the doQuickSort method to sort an int …

Member Avatar
Member Avatar
+0 forum 5

Hello, What is the best way to check my code? I have written a program that counts the swaps required to sort an integer array using the Bubble, Selection, Insertion and Quick sort methods. How can I be absolutely certain that my swap counts are correct? Will someone take a look at my code and make a suggestion? Is there code on the web that will confirm my results? Thanks, Jim

Member Avatar
Member Avatar
+0 forum 4

Hey guys looking for some help with my ArrayTester class... The array is supposed to 1.create a 20 element int array and populates it with random elements in the range 20 through 65 (both inclusive). -I Believe I have already done this. 2.Use the java.util.Random class with a seed of 2621 to generate repeatable output for the data. -I have also already done this 3.The tester class should then test each of these methods(mean, median, mode, max, min, standard divination) -this is where I'm having trouble, I already have the code for the mean, mode, max, min, and standard divination.. …

Member Avatar
Member Avatar
+0 forum 2

Hey guys, I'm trying to understand how radix sort works in C++ : I've looked over the C++ implementation from wikipedia: void radixsort(int *a, int n) { int i, b[MAX], m = a[0], exp = 1; for (i = 0; i < n; i++) { if (a[i] > m) m = a[i]; } while (m / exp > 0) { int bucket[10] = { 0 }; for (i = 0; i < n; i++) bucket[a[i] / exp % 10]++; //accumulate for (i = 1; i < 10; i++) bucket[i] += bucket[i - 1]; //transfer for (i = n - 1; …

Member Avatar
Member Avatar
+0 forum 1

I tried to use a different forum but I was completely out of my league with the responses. I am extrememly new to python. As a project, I'm supposed to ask the user to input a file name, check that the file exists, output the numbers in the file, and sort them for biggest to smallest. The trick is, I can't use built in functions to do the sorting. I have to use this algorithm: for each i from range(n) for each j from range(n-i) if A[j-1]<A[j] swap(A[j], A[j-1]) Here's what I've been playing with: def main(): try: file=open(input("Please enter …

Member Avatar
Member Avatar
+0 forum 4

I am supposed to create a file that will generate 100 random numbers and then sort them. I am stuck on the sorting. I think it would be a really simple solution but i cant seem to figure it out. I have tried the arrays utility and creating a method to sort but I keep getting a lot of zeros and i know that isn't right. I know something around line 32 isnt right. Any help would be greatly appreciated. Thanks! [CODE]import java.util.Random; //import random number generator import java.io.*; import java.util.Arrays; public class NumGen { public static void main (String …

Member Avatar
Member Avatar
+0 forum 12

Hello my fellow Daniwebers! I am having some problems wrapping my head around the task sorting a List(Of CustomType) I have a list containing a custom class. The class contains Two DateTime objects, Start and End. I am trying to sort the list descending so that the shortest timespan will be on the bottom of the list. I am unsure how to write the function that returns the value to sort. I have read Microsoft's documentation [here](http://msdn.microsoft.com/en-us/library/w56d4y5z.aspx) and, as all ways, I am more confused after reading it than I was before I began. This is what I have deducted …

Member Avatar
Member Avatar
+0 forum 2

Not sure if I posted correctly. I am trying to do a bubble sort on a 2D array. I want to sort the array by columns. I get it to compile but it doesn't run correctly. #include <iostream> using namespace std; int main() { int array[10][10]; int col, row; cout<<"Enter numbers to put into row "; for(int i = 0; i < 9; i++){ cin>>row; cout<<"Enter the numbers to put into column "; for(int j = i+1; j < 10; j++){ cin>>col; array[i][j]; } } int maxIndex; for(int i=0; i<size-1;i++) { maxIndex=i; for(int j=i+1;j<size;j++){ if(a[j][col] > a[maxIndex][col]) maxIndex=j; } if(a[i][col] …

Member Avatar
Member Avatar
+0 forum 4

The End.