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 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

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

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

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

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

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

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

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

This is the exercise I have in codelab. I've been going over and over, and just can't see how to do it without an array. Must be something simple that I am missing. Any suggestions? _____ 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 …

Member Avatar
Member Avatar
+0 forum 6

I am trying to sort a certain amount of integers. I have an error in my code. The code is below as well as my error message. Any suggestions of how to fix this? I believe it has to do with it being primitive data rather than an object? `public static void main(String[] args) { int[] intList; int size; Scanner scan = new Scanner(System.in); System.out.print("\nHow many integers do you want to sort? "); size = scan.nextInt(); intList = new int[size]; System.out.println("\nEnter the numbers..."); for (int i = 0; i < size; i++) intList[i] = scan.nextInt(); Sorting.insertionSort(intList); System.out.println("\nYour numbers in sorted …

Member Avatar
Member Avatar
+0 forum 4

Hello I am trying to add two records to an array so I can identify which record has a priority 1 or priority 2. This is not working, how do get this to work? <? //get data from database $query = "SELECT a.street, a.city, a.province, b.dob, b.id1_name, b.id1_value, b.id1_priority, b.id2_name, b.id2_value, b.id2_priority FROM pat_address a LEFT JOIN pat_ident b ON a.patient_id = b.patient_id WHERE a.patient_id = '$patient_id' AND a.deleted = 'N' AND b.deleted = 'N'; $result = mysqli_query ($mysqli, $query); while($row = mysqli_fetch_array($result)) { list($street, $city, $province, $birthday_c, $lang1_code, $id_priority1, $id_name1_c, $id_value1, $id_priority2, $id_name2_c, $id_value2, ) = $row; } //if …

Member Avatar
Member Avatar
+0 forum 3

i made this code to loop number for(int i=0;i<4;i++){ double temp[i]=Math.random() * i*10; system.out.println("Result" +i+ "=>" +temp); } output : Result 0 => 14.3 Result 1 => 11.4 Result 2 => 10.8 Result 3 => 12.4 now, i want to sort by ascending this output based on value with keep original index, so the output like this : Result 2 => 10.8 => 1 Result 1 => 11.4 => 2 Result 3 => 12.4 => 3 Result 0 => 14.3 => 4 how to do this?

Member Avatar
Member Avatar
+0 forum 7

Hi All, Given an array of numbers, I want to find out the 2nd largest number in an array. Can anyone help me to solve the problem? Any help in terms of logic or code would be useful. Thanks, Vishal

Member Avatar
Member Avatar
+0 forum 1

Hello, I have a observer pattern based JTable. With time it is poulated with new data packets. I use addRow functionalities to add my rows. But I want to put always the last coming datapackets at the top. How to do it??

Member Avatar
+0 forum 0

public class Exercise { /** * @param args the command line arguments */ public static void main(String[] args) { String A[] = { "Joseph","Ariana","Xena","Rene","Peter","Diana","Rihanna"}; String B[] = {"Madona","Diddy","Joe","Alice"}; for(int j = 0; j < A.length; j++) { for(int s = j +1; s < B.length; s++) for(int i = 0 ; i < B.length; i++) { if(A[j].compareToIgnoreCase(B[i]) < 0) { } } List<String> list = new ArrayList(Arrays.asList(A)); list.addAll(Arrays.asList(B)); Object[] C = list.toArray(); System.out.println(Arrays.toString(C)); } } } And the out put was like this: run: [Joseph, Ariana, Xena, Rene, Peter, Diana, Rihanna, Madona, Diddy, Joe, Alice] [Joseph, Ariana, Xena, Rene, Peter, …

Member Avatar
Member Avatar
+0 forum 26

I need to modify this movies program so that way the DVDs will be sorted by title at all times (A first thru Z). I need to use Binary Search so I put a method in DVDCollection but I'm probably missing something or calling it incorrectly. The program needs to be sorted by title alphabetically both times it prints. Thank you for your help. The 3 classes of this program are pasted below. (Movies -> DVDCollection -> DVD) [CODE] public class Movies { // Creates a DVDCollection object and adds some DVDs to it. Prints // reports on the status …

Member Avatar
Member Avatar
+0 forum 2

i was watching a tutorial about bubblesort, and i followed all the instructions the difference is that the tutor is using System.out while im using JOPtionPane, please help me thank you help me find my error and help me run it correctly! [CODE]public static void main(String[] args) { // TODO Auto-generated method stub String ctr=""; JOptionPane.showMessageDialog(null,"Enter any 10 numbers:"); int[] points = new int[10]; for (int i=1; i<=10+1;i++){ points[i]=Integer.parseInt(JOptionPane.showInputDialog(null,"num["+i+"];")); ctr = ctr+points[i]+ " "; int[] sortedArray = bubbleSort(points); } int sortedArray = 0; JOptionPane.showMessageDialog(null, "Numbers Entered: "+ctr+"Ascending:"+ sortedArray); } private static int[] bubbleSort(int[] points) { int n=points.length; for(int pass=1; pass<=n;pass++){ …

Member Avatar
Member Avatar
+0 forum 6

Hi friends., Actually I use datagrid to show my result from XML file.I load my data from XML file easily.But i need Sorting method for that and i don`t know how to solve it Please give me solution for that My code is [CODE] Imports System.Data Imports System.Xml Imports System.IO.StringReader Partial Class _Default Inherits System.Web.UI.Page Dim ds As DataSet = New DataSet Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If IsPostBack = False Then Dim dataset As DataSet = New DataSet() dataset.ReadXml(Server.MapPath("~\book.xml")) bookgrid.DataSource = dataset bookgrid.DataBind() End If End Sub Protected Sub bookgrid_SelectedIndexChanged(sender As Object, …

Member Avatar
Member Avatar
-1 forum 6

I am trying to sort a record according to their respective number like this: [CODE] 5 reyes d r 1 2 3 3 delos d k 4 5 6 9 go t r 7 4 5 1 po w w 2 2 2 2 bun b m 3 3 3 [/CODE] then it will become: [CODE] 1 po w w 2 2 2 2 bun b m 3 3 3 3 delos d k 4 5 6 5 reyes d r 1 2 3 9 go t r 7 4 5 [/CODE] here is the definition of the code: [CODE] …

Member Avatar
Member Avatar
+0 forum 8

Hello! I just made an program, but now i have problem with sorting output in the asc. order (int datum) thats date in our language :) [CODE] #include <iostream.h> #include <stdlib.h> struct datum { char dan [32]; char mesec [13]; char leto [5]; void vnosDatum(); void izpisDatum(); }; void datum::vnosDatum() { cout << "Dan: "; cin.ignore(); cin.getline(dan,32); cout << "Mesec: "; cin.getline(mesec,13); cout << "Leto: "; cin.getline(leto,5); } void datum::izpisDatum() { cout << "Datum nakupa: " <<dan << "." << mesec <<"."<< leto << "\n"; } struct racunalnik { datum datum; char ime[10] ; int hitrost_procesorja; int velikost_pomnilnika; int stevilo_jeder; …

Member Avatar
+0 forum 0

I would like to start this post off with, I am not looking for someone to do my homework for me. If I was looking for someone to "do it for me", I would go to one of the sites where you can pay someone to do your work for you. I am trying to learn VB and C#. This is a VB.Net assignment. However, I am looking for guidance or someone to point out my errors (and there are SEVERAL of them from the odd results my game is producing. I am going to paste the assignment requrirements, then …

Member Avatar
Member Avatar
+0 forum 2

Yay guys, it's me again. I am using the code from here: [url]http://www.daniweb.com/software-development/vbnet/code/370426[/url] to sort my listview items. But I want something more 'dynamic': when I click on a header column, I want that it changes the sorting based on the column that has been clicked. here is my code: [CODE=VB.Net]'Classes usadas Imports System.Math Imports System.IO Imports System.Threading.Thread Public Class Main 'Define as vari├íveis Dim CaminhoArquivo As String Private Sub ProcuraDir(sender As System.Object, e As System.EventArgs) Handles btnProcuraPasta.Click 'Exibe o di├ílogo de procura If ProcuraPasta.ShowDialog = DialogResult.OK Then 'Mostra o nome do arquivo na caixa de texto associada Caminho.Text = …

Member Avatar
Member Avatar
+0 forum 3

hey, i'm supposed to prompt a user to enter 6 sets of numbers, find the difference of each set based on which number is greater(so that no negative number will be seen, enter the difference into the array, rearrange the array in ascending order and then print the array. the problem im getting is that it is accepting the numbers but not finding the difference or assigning it to points in the array...can anyone help me?? thanks alot. this is the code i have so far [CODE] #include <stdio.h> main () { int nums[6]; int num1 , num2, i, diff= …

Member Avatar
Member Avatar
+0 forum 3

Hi, I'm a beginner with Java and I need help with an assignment: Write a program that will help the Toronto Blue Jay's scouts decide which players they should draft next year. For each player the scouts have been watching, a record has been prepared showing the player's name, age, position, and batting average. Design a program that will ask the scout to enter information for 10 players into arrays. The program should then check each of the players and display statistics of only those players who are under 25 years old and have a batting average of .280 or …

Member Avatar
Member Avatar
+0 forum 11

I did an experiment regarding sorting of 256.000 random "names" using TListBox component. A friend of mine say that TListBox is faster than my code at sorting, so I wanted to test this out of curiosity. Method of testing. When I have created 256 thousand random textstrings, each 6 characters, I add these into a listbox that is invisible, hence no updating whilst adding. Then I Press a button in order to do only one thing: TListBox.Sorted:=TRUE It takes about 5 seconds, and the control is returned to my form. Does this mean that 256000 purely random strings have been …

Member Avatar
Member Avatar
+0 forum 6

Hi, I want to be able to sort a multidimensional array using its second dimension to sort the first. It is a list of sporting teams with points stored like this: [CODE]$teams[$teamnumber]['points'] $teams[$teamnumber]['players'] $teams[$teamnumber]['name'][/CODE] These teams are to be shown in a league table which is why they needed to be sorted in descending order of points, however the data must not be mismatched or teams may end up with the wrong name, players etc.

Member Avatar
Member Avatar
+0 forum 3

The End.