//Bubble.h #include <iostream> #include <fstream> #include <cstdlib> using namespace std; struct nodeType { int info; nodeType *link; }; class Bubble { public: Bubble(); //constructor //deconstructor //copy constructor //operator= (overloading the = operator) friend istream & operator>> (istream &infile, Bubble & mylist); friend ostream & operator<< (ostream &outfile, const Bubble & alist); int size()const; void bubblesort(); private: nodeType *head_ptr; int manynodes; };

Member Avatar
Member Avatar
+0 forum 8

My name is Leonard E. Norwood Jr. I'm just practicing a simple bubblesort program but this time using classes and pointers with operators >> and << and also an overloaded operator =. I'm merely trying to sort a list of numbers from lowest to highest. And the purpose of the bubblesort is to search for unsorted numbers to compare and swap until the list is fully sorted. This is my list for practice: 29 23 12 39 32 37 41 52 67 59 103 91. You can easily sort that out in your head. I just got one error that …

Member Avatar
Member Avatar
+0 forum 17

Hello. I am having a tough time understanding the concept of double linked list. For now, i understand double linked list has 2 links, one forward and another one previous. data is in the middle. when inserting must check where to insert. if previous is equal to null, then can insert it to previous. Set the previous to be equal to the newly allocated node. I am looking to do a bubble sort using double linked list. I want to understand the concept first then I can do it. Can someone give some usefule links or explain me the concept? …

Member Avatar
Member Avatar
+0 forum 4

Hi, I'm trying to sort a list of names in c++ (first name and last name). I'm running into a couple of problems with my code. I'll post the code first then state my problems. #include <iostream> #include <stdio.h> #include <cstring> using namespace std; const int numNames=3;//this makes the code more flexible, sets the amount of names to sort int main() { char name [numNames][80]; char last_name[numNames][80]; char name_buff [1][80]; cout << "Please enter 3 names to be sorted.\n"; cout<< "\nEntires should be of the format\n"; cout << "First_Name Last_Name." << "\n\n"; for (int i=0; i<numNames; ++i)//use a loop to …

Member Avatar
Member Avatar
+0 forum 5

Hello, I am in the process of creating a program that accepts random numbers, put them in an array and sort them using different types of sorting algorithms. I then passed the array as an argument to the "BubbleSort" function, however, when I try to call the array in the main() function, an error appeared saying "argument of type "int" is incompatible with parameter of type "int *" Why did that appear? Did I overlook something in the program? It's not finished yet, but here it is: #include <iostream> using namespace std; void BubbleSort(int arr[], int n); int main() { …

Member Avatar
Member Avatar
+0 forum 6

Hi! I'm writing a program in C++ where the user is asked to enter a list of ten names and cities of residence in the format <firstname> <Surname> <city>. I then have to sort the list by city and then in each city group alphabetically by name, using Bubblesort. I'm able to extract each of the three components from the strings, but now I'm really lost on how to implement the Bubblesort correctly. All of the notes I have seen are for sorting numbers, not letters. Can anyone help me or offer suggestions as to how to sort the names? …

Member Avatar
Member Avatar
+0 forum 9

Hi, I'm writing a program in C++ to ask the user for a list of ten names and cities of residence in the format <firstname> <Surname> <city>. The amount of spaces between each doesn't matter as I will be using isspace. then i have to sort the list by city and then in each city group alphabetically by name. I'm able to extract each of the three components from the strings, but now I'm not sure on how to incorporate sorting into this, we have to use bubble sort. This is what I have so far [CODE]#include <iostream> #include <stdio.h> …

Member Avatar
Member Avatar
+0 forum 13

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

Hello, I'm hoping you guys can help. I have a double linked list, and i am trying to add a bubble sort to it,I am really new to java, I've been able to do a bubble sort with great easy whilst using binary trees, but now i'm using a double linked list, and i don't have a clue how to do it. It's been driving me mad, and i really need help on this. Any help will be much appreciated.

Member Avatar
Member Avatar
+0 forum 1

[CODE] #include <iostream> #include <string> #include <cctype> #include <iomanip> #define N 36 using namespace std; string EraseWhiteSpaces(string &str_nospaces) { int i; for (int i=0;i<str_nospaces.length();i++) { if (str_nospaces[i]==' '||(str_nospaces[i]=='\t')) { str_nospaces.erase(i,1); i--; } } return str_nospaces; } string ConvertToLowerCase(string &str_lowercase) { int i; for (i=0;i<str_lowercase.length();i++) str_lowercase[i]=tolower(str_lowercase[i]); return str_lowercase; } void SortedFrequences(int frequences[],char chars[]) { int i,j,tmp1; char tmp2; for (i=0;i<N;i++) { for (j=i+1;j<N;j++) { //THE PROBLEM IS HERE!!!!!!!! if (frequences[i]<frequences[j]) { tmp1=frequences[i]; frequences[i]=frequences[j]; frequences[j]=tmp1; tmp2=chars[i]; chars[i]=chars[j]; chars[j]=tmp1; } } } cout<<"character: frequency:"<<endl; for (i=0;i<N;i++) { if (frequences[i]==0) break; cout<<chars[i]<<":"<<frequences[i]<<endl; } } int main() { int i,k=0,l=0,j; string str,fstr=""; char xaraktires[N]; int …

Member Avatar
Member Avatar
+0 forum 6

I have to create a program in C and not C++, that allows the user to create a file that stores names and numbers, displays them and sorts the dates by names or numbers using Bubble sorting. I know how to create a program that sorts names and numbers that are entered from a keyboard, but don't know how to do it whit a file. If anyone knows please at least show me an example. Thanks. This is the program i written so far. [CODE]#define _CRT_SECURE_NO_WARNINGS #include<stdlib.h> #include<stdio.h> #include<conio.h> FILE *f; struct dates{ char name; int num; }list; int s,i; …

Member Avatar
Member Avatar
+0 forum 2

hi I'm new I got some questions about bubble-sort, so I registered here. I'm currently working on this program (bubble-sort) so I looked up some example codes and I found this here, which is practically the right thing I'm looking for. But I have some questions, like 1. How would [B]printf("%2d. Pass: ", i-1)[/B]; be with [B]cout[/B], since I'm not really familiar with printf as I always worked with cout. my guess would be [B]cout<<("Pass: ", i-1);[/B] but then there is no space between each number [B]printf("%3d", z[k]);[/B] I think it should be [B]cout<<z[k]; [/B] 2. How would I program …

Member Avatar
Member Avatar
+0 forum 2

[CODE]package com.abc.text; public class StringProcessing { /** * Returns the number of non-null strings in the set. * If null or a zero-length array is passed in, then zero is returned. * If a slot in the array is null, then it is ignored (not counted). */ public static int getCount(String[] set) { } /** * Returns the total length of all the non-null strings in the set. * If null or a zero-length array is passed in, then zero is returned. * If a slot in the array is null, then it is ignored (not counted). */ public static …

Member Avatar
Member Avatar
+0 forum 2

Can someone show me what bubble-sorting an int[] of { 5, 4, 3, 2, 1 } looks like? I have to place it inside [CODE]public class SortIntArray { // this method needs your code to be added to work public static void sort(int[] list) {[/CODE] with no calls to any other methods or classes. I've been working on an assignment for two days and haven't been able to make any progress.

Member Avatar
Member Avatar
+0 forum 5

Hey all, I have an assignment that was assigned for the week that I could use some help on (not asking for someone to do it for me, just help with the step-by-step). Below is the requirements: 1) Create a new Java Project named whatever you'd like in your existing Eclipse Workspace. 2) In this project create a class named SortIntArray in the com.abc.sort package. 3) Paste in the code below overwriting everything in your initial SortIntArry.java file. 4) Except for the sort(int[]) method, all the other methods are complete as is and should NOT be altered. 5) The only …

Member Avatar
Member Avatar
+0 forum 5

i want to ask something about my assignment. heres the code [CODE]#include <stdio.h> int main() { int nilaiuts[5],nilaiuas[5],nilaitugas[5]; int i; float total=0; printf("Masukkan nilai UTS mahasiswa [5 mahasiswa] :\n"); // proses memasukkan data ke array for (i = 0; i < 5; i++) { printf("Mahasiswa %i : ", i+1); scanf("%i",&nilaiuts[i]); // Memasukkan nilai ke dalam elemen array } printf("\nNilai UTS mahasiswa yang telah Anda masukkan adalah : "); // proses menampilkan data dari array for (i = 0; i < 5; i++) { printf("\nMahasiswa %i : %i",i+1, nilaiuts[i]); } printf("\n\nMasukkan nilai UAS mahasiswa [5 mahasiswa] :\n"); // proses memasukkan data …

Member Avatar
Member Avatar
+0 forum 1

/*Does the Bubble sort algorithm above sort the array into ascending or descending order?*/ void BubbleSort(int Data[ ],int ArraySize) { char sorted = ‘f’; int pass,a,Temp; pass = 1; while (sorted=='f' && pass<=ArraySize-1) { sorted = 't'; for (a=0;a<ArraySize - pass;a++) { if (Data[a] < Data[a+1]) { Temp = Data[a]; Data[a] = Data[a+1]; Data[a+1] = Temp; sorted = 'f'; } } pass++; } }

Member Avatar
Member Avatar
+0 forum 1

The method below for bubble sort should work, it displays the unsorted array fine, but for the sorted array it only displays one of the numbers. It seems to have just skipped over the other elements in the array. Here is a sample output: [COLOR="Green"]How many random even integers would you like to generate? 6 Unsorted: 196 166 68 14 68 176 Sorted: 196 5[/COLOR] [CODE]public static void bubbleSort (int [] array, int length) { int temp, i, j; System.out.println("Unsorted: "); for (i=0; i<array.length; i++) { System.out.println(array[i]); } for (i=0; i<length-1; i++){ for (j=0; j<length-1; j++) if (array[j]>array[j+1]){ temp=array[j]; array[j]=array[j+1]; …

Member Avatar
Member Avatar
+0 forum 5

hey guys,been browsing this site for a few weeks,but this is my first post. As you might guess by my problem I'm a C++ noob. I'm tryin to make a program in which the user inputs an array of double, I then use bubble sort to to get it into descending order, and output it in the correct order. the issue I'm having is that after I sort the array, only the first number comes out as a double, the rest are all integers. How can I fix it so that all the numbers come out at the end as …

Member Avatar
Member Avatar
+0 forum 11

The End.