473,503 Members | 12,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2-D Alphabetical Bubble Sort C++

16 New Member
Using Visual Studio 2005, right now my only error (for now) is something with the function prototype that I can't figure out for the life of me. Every data type is unexpected for my function. I'm sure there's more errors but I'll figure those out if I can just get it to compile.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. const int MaxNames = 21;
  7. const int MaxChars = 16;
  8. char Array[MaxNames][MaxChars];
  9. char temp[MaxNames][MaxChars];
  10. int i, j, pass,
  11.  
  12. void Sort(char Array[][MaxChars], char temp[][MaxChars], pass);
  13.  
  14. void main()
  15.     {
  16.     cout << "-------------------------------------------------------------------------------" << endl;
  17.     cout << "This program will allow you to enter names and sort them in alphabetical order." << endl;
  18.     cout << "-------------------------------------------------------------------------------" << endl;
  19.     cout << "First, how many sets of names you will enter? (Must be less than 20): ";
  20.     cin >> pass;
  21.  
  22.     if (pass==0)
  23.         cout << "FATAL ERROR: You have entered 0 or a character. Please restart the program and try again." << endl;
  24.         system("PAUSE");
  25.  
  26.     while (pass < 0 || pass > 20)
  27.         { 
  28.         cout << "ERROR: You cannot enter less than 1 or more than 20 numbers. Try again: ";
  29.         cin >> pass;
  30.         }
  31.  
  32.     for (i=0; i<pass; i++)
  33.         {
  34.         cout << "Enter a name: ";
  35.         cin.getline(Array[i],MaxChars);
  36.         }
  37.  
  38.     cout << endl << "Unsorted: ";
  39.         for (int i=0; i<pass; i++) 
  40.             {
  41.             for (int j=0; j<MaxChars; j++)
  42.                 cout << Array[i][j];
  43.             }
  44.  
  45.     Sort(Array[MaxNames][MaxChars], temp[MaxNames][MaxChars], pass);
  46.  
  47.     cout << endl << "Sorted: ";
  48.         for (int i=0; i < pass; i++) 
  49.             {
  50.             for (int j=0; j<MaxChars; j++)
  51.                 cout << Array[i][j];
  52.             }
  53.     }
  54.  
  55. void Sort(char Array[MaxNames][MaxChars], char temp[MaxNames][MaxChars], int pass)
  56.     {
  57.     bool IsSorted(false);
  58.     while(!IsSorted)
  59.         {
  60.         IsSorted=true;
  61.         for (i=0; i<pass-1; i++)
  62.             {
  63.             if (Array[i][0]>Array[i+1][0])
  64.                 {
  65.                 for (i=0, j=0; i<MaxNames-1, j<MaxChars-1; i++, j++)
  66.                     {
  67.                     temp[i][j]=Array[i][j];
  68.                     Array[i][j]=Array[i+1][j];
  69.                     Array[i+1][j]=temp[i][j];
  70.                     IsSorted=false;
  71.                     }
  72.                 } 
  73.             }
  74.         } 
  75.     }
  76.  
Mar 28 '07 #1
1 5260
Randeh
16 New Member
Nevermind! Got it. Missed a semi-colon.
Mar 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

34
7273
by: Mark Kamoski | last post by:
Hi-- Please help. I need a code sample for bubble sort. Thank you. --Mark
4
3646
by: Chris | last post by:
I have a bubble sort for a 2-dimensional array that sorts a string,number pair based on the number. The code for the sort is as follows: Private Sub SortArray(ByRef roundarray(,) As String)...
2
6512
by: yenra | last post by:
..how can I insert entry in a linked list and arrange my entries according to the name in alphabetical order? I need to make a student record which contains the name, yr level and course of the...
7
2703
by: Ron Adam | last post by:
I have several applications where I want to sort lists in alphabetical order. Most examples of sorting usually sort on the ord() order of the character set as an approximation. But that is not...
4
5525
Cyberdyne
by: Cyberdyne | last post by:
In your All Programs Menu, some of your programs are in alphabetical order and others are not. This makes it very difficult to seek out a program that may be hidden in a maze of program folders and...
0
1925
by: Randeh | last post by:
Using Visual Studio 2005. Finally got this thing to compile, but now it prints an empty blank row for the first pass, so I guess there's an error somewhere in the function I have to show the Array. ...
6
4901
by: Randeh | last post by:
Here's my working code for simple a 2-D alphabetical bubble sort. All I need now is to just make it case insensitive (ignores capitalization) and I've been trying to throw toupper or tolower in...
12
8619
by: midknight5 | last post by:
Hello everyone, I am familiar with a normal bubble sort when dealing with an array of number but I am unsure as how to implement a sort when I have an array that is filled with classes which hold...
7
7125
by: mahdiahmadirad | last post by:
Hi dears! I wrote a simple bubble sort algorithm. it works properly when we compare full arrays but i want to sort a 2d array according to a specific part of array. it has some problem to swapping...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.