Here is the code for [B][COLOR="Red"]Insertion Sort, Bubble Sort and Selection Sort[/COLOR][/B] [B]Insertion Sort[/B] [CODE] #include <stdio.h> main() { int i,j,key; int a[5]={5,2,3,4,1}; for(i=1;i<5;i++) { key=a[i]; while(i>0 && a[i-1]>key) { j=a[i]; a[i]=a[i-1]; a[i-1]=j; --i; } } int k; for(k=0;k<5;k++) {printf("%d ", a[k]);} printf("\n"); } [/CODE] [B]Bubble Sort[/B] [CODE] #include <stdio.h> main() { int i,j,x; int a[5]={5,2,3,4,1}; for(i=0;i<5;i++) { for(j=i+1;j<5;j++) { if(a[i]>a[j]) { x=a[i]; a[i]=a[j]; a[j]=x; } } } int k; for(k=0;k<5;k++) {printf("%d ",a[k]);} printf("\n"); }[/CODE] [B]Selection Sort[/B] [CODE] #include <stdio.h> main() { int i,j,x,min,k; int a[5]={5,3,2,4,1}; for(i=0;i<5;i++) { min=i; for(j=i+1;j<5;j++) { if(a[min]>a[j]) { min=j; } x=a[min]; a[min]=a[j]; a[j]=x; } } …

Member Avatar
Member Avatar
+0 forum 19

The bubble sort is slow and I thought it would be interesting to visualize the progress as it sorts an array of integers.

Member Avatar
Member Avatar
+5 forum 11

I am creating 30 random from last function and the last function have pass the information to this one. I am using the bubble sort because i want to make a mode. But mode is not idea here. Anyway, it run but it show some crazy output. Here is the output: -1969384903, -1969384675, -1957005749, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, here is the random number: 17-78-81-10-98-67-30-87-63-15 73-63-50-51-61-89-20-89-27-1 6-56-47-91-35-16-97-13-39-81 can someone tell me what i did wrong? void mode(int mode[],int …

Member Avatar
Member Avatar
+0 forum 3

Can any one tell me what I am doing wrong. I am sorting a single linked list. void ll::sort() { for(int i=0;i<size-1;i++) {node *cptr = fptr; for(int j= 0;j<size-1;j++) { if((cptr->no) > (cptr->nxt->no)) { if(cptr == fptr) { node *c2ptr = cptr->nxt; cptr->nxt=c2ptr->nxt; c2ptr->nxt=cptr; fptr = c2ptr; } else { node *c2ptr = cptr->nxt; node *tptr = fptr; while(tptr->nxt!=cptr) { tptr=tptr->nxt;} cptr->nxt=c2ptr->nxt; c2ptr->nxt=cptr; tptr->nxt=c2ptr; } } cptr=cptr->nxt; } } }

Member Avatar
Member Avatar
+0 forum 8

I'm trying to modify a Bibblesort code I'm writing that will count the number of instances and print out a seperate line for each instance and how many occurances it had. def BubbleSortList(MyList): ComparisonCounter = 0 for j in range ( len(MyList)): for i in range ( len(MyList)-1-j ): if MyList [i+1] < MyList[i]: MyList[i] , MyList[i+1] = MyList[i+1] , MyList[i] #Swapping out the numbers. Nlist = MyList.index(MyList[j]) Count = MyList.count(MyList[j]) ComparisonCounter += 1 print "Instances for " + str(MyList[j]) + " occures " + str(Count) + " time/s" print "The comparison took place " + str(ComparisonCounter)+ " times." #Printing …

Member Avatar
Member Avatar
+0 forum 5

Hi guys, I got this from my teacher and im really confused. could anyone point me in the right direction? Thanks > What does it do? > > This time I'm looking for an overall summary, in one sentence, with the word "by" in the middle: > "This function ..........., by ................ ." > > This function takes a list of numbers as an argument, and returns a list of numbers. > To help you figure it out, cut out 5 or 6 pieces of paper, write some numbers on them, put them on a table, and run the algorithm …

Member Avatar
Member Avatar
+0 forum 3

Hi everybody, Just wondering if it is possible t hat we can change the text size in balloon or bubble message or whatever you call it the one we create useing "trayicon.displaymessage("message", "message", message.info);Highly appreciate if someone could help me out. Thanks.

Member Avatar
Member Avatar
+0 forum 4

Hello everyone; I am new to Python. How can we explain this code step by step. I couldn't understand some parts. myList=[43,21,12,80,3,2,35] end=len(myList)-1 while (end!=-1): swapped=-1 for i in range(0,end): if myList[i]>myList[i+1]: temp=myList[i] myList[i]=myList[i+1] myList[i+1]=temp swapped=i end=swapped print(myList)

Member Avatar
Member Avatar
+1 forum 2

According to the Sunday Telegraph [newspaper yesterday](http://www.telegraph.co.uk/technology/facebook/9276699/Facebook-IPO-fight-back-begins-share-price-implausible-says-analyst.html ) "Morgan Stanley, Facebook’s lead financial adviser, ended the day with 162m shares, worth $6.16bn. Other banks including JP Morgan and Goldman Sachs also bought shares, ending the day with $3.2bn and $2.4bn holdings respectively" which is kind of worrying when you step back and realise that Wall Street were propping up the share prices on the much hyped first day of trading. Indeed, as a result of that $100 billion Facebook valuation, there is now much talk of another tech bubble and whether or not it's about to burst. ![dweb-facebook](/attachments/small/0/dweb-facebook.jpg "align-right") Writing …

Member Avatar
Member Avatar
+0 forum 9

Hi, everyone! This is my first post ever here in Daniweb. I experienced a problem in printing the sorted array of 5 numbers, as the following code only prints the first iteration of the loop, and it does not print the array input. Here's the code: section .data i db 0 ; Value to be incremented question db 'Enter a number: ' ; Prompt questionLen equ $-question newLine db 10, 10, 0 ; New blank line newLineLen equ $-newLine section .bss num resb 5 ; Array of size 5 counter resb 1 ; Value to be incremented counter2 resb 1 …

Member Avatar
+0 forum 0

I trying to sort an array ising php but this code is not working. can any body tell me whats wrong with this code, is my logic is right or wrong. I don't know much about Php as I am new to learning php <? php $a= array(12,5,78,10,63,11); $size=$sizeof($a); for($i=0;$i<=$size;$i++) { for($j=$i+1;$j<$a[$i];$j++) { if($a[$i]>$j) { $temp=$a[i]; $a[$i]=$j; $j=$temp; } } } for($i=0;$i<=$size;$i++) { echo $a[$i]; echo"<br/>" } ?>

Member Avatar
Member Avatar
+0 forum 3

hi everyone!!! I am trying to write a code for list of names to be sorted in alphabetical order. can anybody please tell me what I am doing wrong. and one more thing , is it possible to bubble sort a names in unspecified number of entries? and if it is possible how will the program know where is the end of the list? I was also wondering if I could do bubble sort with strings? many thanks in advance. here is what I have got so far #include <iostream> using namespace std; int main() { char name[3][30]; int i, …

Member Avatar
Member Avatar
+0 forum 1

please tell what am I doing wrong. #include <iostream> using namespace std; int main() { char name[3][30]; int i, j; for(i=0;i<=2;i++) { cout << "Please enter name: "; cin >> name[i]; } for(i=0;i<=1;i++) { for(j=i+1;j<=2;j++) { char temp; if(name[i] > name[j]) { temp = name[i]; name[i] = name[j]; name[j] = temp; } } } for(i=0;i<=2;i++) { cout << endl << name[i] << endl; } cin.ignore(); cin.get(); //system("pause"); }

Member Avatar
Member Avatar
+0 forum 3

hello! i have written a program to read in a text file and then ask the user to process the file with a different sorting method. so far i have been able to get my program to read in the file but my bubble sort seems to not be sorting the elements right. ive tried thinking of as many solutions as possible but im not sure whats wrong.the text file looks like this 1 65 44 34 23 6 any help or ideas on where to start looking for the problem would be greatly appriciated. /****************************************************** * * Program3.cpp Author: …

Member Avatar
Member Avatar
+0 forum 2

I was asked to create a program that enters numbers and displays the before sorting order, and the sorted order displaying the previous node address and the next node address. I was told not to swap the data inside the nodes, but move the nodes themselves. I have a problem with the sorting part because I certainly have no idea how to swap pointers. Here is my code so far: #include <iostream> #include <iomanip> using namespace std; typedef struct node { int DATA; node *NEXT; }; node *HEAD = NULL; void Create(int data); void Display(); void Sort(); int main() { …

Member Avatar
Member Avatar
+0 forum 15

I'm trying to make a bubble sort to sort numbers like 3.2, 5.8, etc(double / float numbers). I have this code so far, but I'm still trying to learn and don't know why my code isn't working the way I think it should. Any help is appreciated. [CODE]using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Bubble { class Bubble { // array to hold values private double[] values = new Double[10]; // number of elements private double elements; // Bubble Sort Algorithm public void sortBubble() { double number; double number1; double temp; double one = 1.0; for (number = …

Member Avatar
Member Avatar
+0 forum 5

Need help making a module that sorts 4 arrays this how it started out void dataSort (float sLengthArray[],float rSlopeArray[],float speedArray[], float size) { void swap (int *x,int *y); int pass,j; for (pass=0;pass < size-1; pass++) { for (a = 0;j< size-1; j++) { if (slengthArray[j] > slengthArray[j + 1]) { swap(&slengthArray[j],&slengthArray[j+1]); } } } } void swap ( int *x,int *y) { int hold=*x; *x = *y; *y = hold; }

Member Avatar
Member Avatar
+0 forum 8

need to make a function that sorts integers from smallest to largest without using the sort function in python python must open a file with integers one per line store the data in a list then print the unsorted list then bubble sort code sorts the list from smallest to largest then print the sorted list p.s. am new to python

Member Avatar
Member Avatar
+0 forum 1

Hi All, Can we use CSS to make rounded corner or bubble speech text area using CSS? I already have my application generating code to show a rectangle, and I want it to look more appealing. Any suggestions are welcome

Member Avatar
Member Avatar
+0 forum 5

so. . . i guess you could say i'm kinda new here but. . . this site really helps me alot this past few days and i decided to join... i was surfing all over the internet and i can't find what's the problem with my program. this always says i need to input something inside the "[]" but i'm passing it to a function bubble sort . .. . i can't explain it well . . . i tried using quicksort but the same problem occurs. . . . can someone help me? here's the code. [CODE]#include <cstdlib> #include …

Member Avatar
Member Avatar
+0 forum 5
Code Snippet Bubble Sort

This is yet another bubble sort.

Member Avatar
Member Avatar
+0 forum 6

Hi guys, this is my first post here, and I'd love any feedback you guys can give me. I'm writing a basic program that bubble sorts its ints in an array to ascending order, then resorts some of those specific ints to the element of the position they represent. What I mean by this is that if say the int 3 is the content of the zero element of my array after bubble sort, I want to move it to the second element so it would print out third. However, I want to keep the rest of the ints in …

Member Avatar
Member Avatar
+0 forum 2

How do I properly bubble sort through a text file by assigning the values to an array. In the code below I tried to assign the values from the text file to a string while there is still something to fetch. Then I used a for loop to assign the one that I have fetch to the array. [CODE] ttry{ int i; String ss; FileReader fr; fr = new FileReader (new File("F:\\players.txt")); BufferedReader br = new BufferedReader (fr); while ((ss = br.readLine()) != null) { String[] sv = ss.split(" "); String splayer_name=sv[1]; String s_player_score=sv[2]; for(int xy=0;xy<player_name.length;xy++){ player_name[xy]=splayer_name; player_score[xy]=Integer.parseInt(s_player_score); } int …

Member Avatar
Member Avatar
+0 forum 5

I have been told to sort an array of structure(student) depending on one of its members(per) using bubble sort. I need to sort the 'student' structure in descending order of 'per'. Please help. I'm stuck!! [CODE] #include<stdio.h> #include<conio.h> struct student { char sname[20],dept[25]; int rollno; float per; }s[30]; void accept(int ); void bubble(int[],int); void print(); int main() { int n; printf("\nHow Many Students Info ??"); scanf("%d",&n); printf("\n"); accept(n); print(n); bubble(s[],n); getch(); return (0); } void print(int no) { int i; for(i=0;i<no;i++) { printf("\n%d. Name :: %s\n Department :: %s\n Roll No. :: %d\n Percentage :: %f\n\n",i+1,s[i].sname,s[i].dept,s[i].rollno,s[i].per); } } void accept(int …

Member Avatar
Member Avatar
+0 forum 1

So uhm...I want to do the bubble sort and i found a code but actually i don't really know what's missing...ok...sorry but i am just a newbie and not so average of logic(lol. :p). My goal here is to complete this code, 'cause i tried to run it but it has an error saying... [I]undefined symbol _main in module c0.ASM[/I] and the code is : [CODE]Bubblesort (int data[],int n) { int tmp,i,j; for (i=0; i<n-1; i++) { for (j=0; j<n-i-1; j++) if (data[j] > data[j+1]) { tmp = data[j]; data[j] = data[j+1]; data[j+1] = tmp; } } getch(); return 0; …

Member Avatar
Member Avatar
+0 forum 3

Hi... i have a little problem on my code... HI open a txt that have this: LEI;7671;Maria Albertina da silva;xxxx@gmail.com; 9;8;12;9;12;11;6;15;7;11; LTCGM;6567;Artur Pereira Ribeiro;fdsdfsd@gmail.com; 6;13;14;12;11;16;14; LEI;7701;Ana Maria Carvalho;asasssas@gmail.com; 8;13;11;7;14;12;11;16;14; -------------------------------------------------------------------------------- LEI, LTCGM are the college; 7671, 6567, 7701 is student number; Maria, Artur e Ana are the students name; [email]xxxx@gmail.com[/email], ...@gmail are emails from students; the first number of every line is the total of classes that students have; after that is students school notes; example: College: LEI Number: 7671 Name: Maria Albertina da Silva email: [email]xxxx@gmail.com[/email] total of classes: 9 Classe Notes: 8 12 9 12 11 6 15 …

Member Avatar
Member Avatar
+0 forum 2

It provides the average grade of an student. Assignment: How many students are in the class ? 3 Enter five test scores for student number 1 80 90 70 90 80 The average for student number 1 is 85 Enter five test scores for student number 2 100 60 60 90 80 The average for student number 2 is 82.5 Enter five test scores for student number 3 90 70 50 70 90 The average for student number 3 is 80 **My problem is getting the average to come out as the average?? This is my only hang up, I've …

Member Avatar
Member Avatar
+0 forum 4

I was trying to Compare the 5 Sorting Algorithms using 4 test cases. [U]Sorting Algorithms[/U] [LIST=1] [*]Selection Sort [*]Insertion Sort [*]Bubble Sort [*]Quick Sort [*]Merge Sort [/LIST] [U]Test cases[/U] [LIST=1] [*][URL="http://the.nube.googlepages.com/Sort.Analysisplot1.svg"]Random Data [/URL](completed) [*]Reverse Sorted Data (completed) [*]Almost Sorted Data (can't generate Data) [*]Highly Repetitive Data (can't generate Data) [/LIST] At first I chose C++ which went to disaster and i finally end up using Octave. I successfully tested for [B][U]Random[/U] and [U]Reverse Sorted Data[/U] [/B]. But in other 2 Couldn't even generate data..... the what i have done so far have been attached with the post.... i have rename …

Member Avatar
Member Avatar
+1 forum 1

The End.