![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
help with Bubble sort program that uses vectors instead of arraysHeader file
CPP / C++ / C Code:
my cpp file for the functions CPP / C++ / C Code:
this is my main cpp file CPP / C++ / C Code:
my program needs to sort vectors instead of arrays but it seems to get errors need some help? am i on the right track or far off? |
|||
|
#2
|
|||
|
|||
Re: help with Bubble sort program that uses vectors instead of arraysQuote:
__________________
Please read http://www.gidforums.com/t-5566.html. They were written to help you create a request that is readable and has enough information we can actually tell what you need help with. |
|
#3
|
|||
|
|||
Re: help with Bubble sort program that uses vectors instead of arraysbub1.cpp
c:\program files\microsoft visual studio\myprojects\new\bub1.h(17) : error C2143: syntax error : missing ';' before '<' c:\program files\microsoft visual studio\myprojects\new\bub1.h(17) : error C2501: 'vector' : missing storage-class or type specifiers c:\program files\microsoft visual studio\myprojects\new\bub1.h(17) : error C2059: syntax error : '<' c:\program files\microsoft visual studio\myprojects\new\bub1.h(17) : error C2238: unexpected token(s) preceding ';' c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(12) : error C2065: 'testData_' : undeclared identifier c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(12) : error C2228: left of '.resize' must have class/struct/union type c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(20) : error C2065: 'size' : undeclared identifier c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(26) : error C2228: left of '.resize' must have class/struct/union type c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(29) : error C2109: subscript requires array or pointer type c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(29) : error C2106: '=' : left operand must be l-value c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(36) : error C2065: 'vectorSize' : undeclared identifier c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(36) : error C2541: delete : cannot delete objects that are not pointers c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(42) : error C2065: 'vector' : undeclared identifier c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(42) : error C2062: type 'int' unexpected c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(43) : error C2065: 'output' : undeclared identifier c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(46) : error C2228: left of '.size' must have class/struct/union type c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(47) : error C2228: left of '.size' must have class/struct/union type c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(4 c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(4 c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(50) : error C2109: subscript requires array or pointer type c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(50) : error C2102: '&' requires l-value c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(50) : error C2109: subscript requires array or pointer type c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(50) : error C2102: '&' requires l-value c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(61) : error C2447: missing function header (old-style formal list?) c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(70) : error C2228: left of '.size' must have class/struct/union type c:\program files\microsoft visual studio\myprojects\new\bub1.cpp(71) : error C2109: subscript requires array or pointer type Error executing cl.exe. bub1.obj - 26 error(s), 0 warning(s) |
|
#4
|
||||
|
||||
Re: help with Bubble sort program that uses vectors instead of arraysRead this tutorial in using vectors.
This will help you fix many of your errors: Using Vectors In your header file, Instead of CPP / C++ / C Code:
Use CPP / C++ / C Code:
Next: Remember the scope of variables. If you use output in one function, it is not available in the other. And, Use clear() in vector to free up memory. so instead of CPP / C++ / C Code:
You can use this: CPP / C++ / C Code:
Use int main() instead of void main(). You can find why here.... Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#5
|
|||
|
|||
Re: help with Bubble sort program that uses vectors instead of arraysbub1.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\new\bub1.cpp(37) : error C2065: 'testdata_' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\new\bub1.cpp(37) : error C2228: left of '.clear' must have class/struct/union type C:\Program Files\Microsoft Visual Studio\MyProjects\new\bub1.cpp(69) : error C2228: left of '.size' must have class/struct/union type C:\Program Files\Microsoft Visual Studio\MyProjects\new\bub1.cpp(70) : error C2109: subscript requires array or pointer type Error executing cl.exe. bub1.obj - 4 error(s), 0 warning(s) still having trouble with theses four errors |
|
#6
|
||||
|
||||
Re: help with Bubble sort program that uses vectors instead of arraysHi sasuke,
Quote:
Please post the lines where you get the error message. We cant figure it out by just looking at the errors. Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#7
|
|||
|
|||
Re: help with Bubble sort program that uses vectors instead of arraysfor (int i =0; i < output.size(); i++)
C:\Program Files\Microsoft Visual Studio\MyProjects\new\bub1.cpp(69) : error C2228: left of '.size' must have class/struct/union type cout<<"\n"<<output[i]<< endl; C:\Program Files\Microsoft Visual Studio\MyProjects\new\bub1.cpp(70) : error C2109: subscript requires array or pointer type those are the two errors i have left |
|
#8
|
||||
|
||||
Re: help with Bubble sort program that uses vectors instead of arraysQuote:
Quote:
__________________
The 3 Laws of the Procrastination Society: 1) Never do today that which can be put off until tomorrow 2) Tomorrow never comes |
|
#9
|
||||
|
||||
Re: help with Bubble sort program that uses vectors instead of arraysI think the problem is here:
CPP / C++ / C Code:
The answer is this:: Quote:
and why do you use the output variable? Use the testData_ variable instead. Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#10
|
||||
|
||||
Re: help with Bubble sort program that uses vectors instead of arraysHi Sasuke,
Even if you modify those things, your code is wrong in bubble sort functions and is confusing. The code you have written for arrays will not be the same in the case of vectors. Since you are unable to find an answer using vectors and your code is quite confusing, i'll modify the entire thing so that it remains simple. Here we go: First the header file: Remember your previous post issues about the header file? Here is the modified header file: CPP / C++ / C Code:
You already know what is #ifndef..etc in your previous thread. Here are the modifications i did in the program: Renamed the vector as testData only instead of testData_ to make coding easier. Added #ifndef..etc to the code. Removed your swap function. Added the modified swap code in the bubble_Sort function itself. Now to the cpp file: Removed the other cpp file used to define the functions. I used the main cpp file instead as in the previous post to maintain simplicity. Here is the constructor definition: CPP / C++ / C Code:
Get the input size. Resize the vector. Generate random numbers and store them in the vector. You can add code for you constructor with argument if you want to.(i didnt do it); Now to the destructor: CPP / C++ / C Code:
Your bubble_Sort() function: CPP / C++ / C Code:
Didnt use a swap function. I entered the code here itself. Note how the vector is used here. Your put() function: CPP / C++ / C Code:
Your main function: CPP / C++ / C Code:
Please read the comments for more information about the program. So, summarising, we have the main.cpp file as: CPP / C++ / C Code:
Just include the bub1.h file. Define the class functions. Please dont take it for granted. I have done this for you only to make you understand. If you have any doubts, please clarify. Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
Recent GIDBlog
Problems with the Navy (Officers) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| need help with bubble sort for c++ | sasuke101 | C++ Forum | 2 | 21-Sep-2005 20:12 |
| Type casts ? | kai85 | C++ Forum | 12 | 23-Jun-2005 12:04 |
| [Tutorial] Pointers in C (Part I) | Stack Overflow | C Programming Language | 1 | 08-Apr-2005 18:35 |
| [GIM] gim.h | dsmith | C Programming Language | 0 | 18-Jan-2005 08:48 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 07:10 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The