473,657 Members | 2,474 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 5267
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
7303
by: Mark Kamoski | last post by:
Hi-- Please help. I need a code sample for bubble sort. Thank you. --Mark
4
3670
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) Dim i, j, x As Integer x = roundarray.GetUpperBound(0) Dim tempname, tempnumber As String For i = 0 To x - 1 For j = i + 1 To x
2
6522
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 student. Is bubble sort applicable in this problem?if yes, can anyone help me how to implement it..tnx..
7
2707
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 always what you want. The solution of converting everything to lowercase or uppercase is closer, but it would be nice if capitalized words come before lowercase words of the same spellings. And I suspect ord() order may not be correct for some...
4
5530
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 files. The solution is simple: have the computer re-sort the menu. When you install new programs, Windows XP tacks them to the end of your All Programs menu, rather than inserting them in the correct alphabetical order. So every so often you have...
0
1928
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. It basically prints out the user prompt, then after you enter the number of names, such as 3... it prints out: Enter a name: Enter a name: Enter a name: instead of Enter a name:
6
4910
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 there but it never seems to work properly. Any ideas? void SortArray(char Array, int pass) { bool swap; int temp; do { swap=false;
12
8634
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 multiple values. I need to make a bubble sort that reaches into an array called Tree which has in each storage location a class called Christmas Tree which have the values Species, Height, trunkDiameter, and costPerFoot. The sort will need to sort...
7
7139
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 this array. please help me. my scenario: assume that we have a big 2d char array for example students for 20 persons an 30 character for each person. first 15 chars contains first name and the rest is last name. no i want to sort this array...
0
8413
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8740
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6176
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.