BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sort Array Help!
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Cenk
Guest





PostPosted: Fri Dec 09, 2005 8:27 pm    Post subject: Sort Array Help! Reply with quote



Hi,

Is there a library or a function to sort one or two dimentional (int or
double) arrays? i found the code below but it gave error!
i think <algorithm> could not be recognized!
Please help.
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
int a[7] = {23, 1, 33, -20, 6, 6, 9};

sort(a, a+7);

for (int i=0; i<7; i++) {
cout << a[i] << " ";
}

return 0;
}


Back to top
Rudy Velthuis [TeamB]
Guest





PostPosted: Fri Dec 09, 2005 8:37 pm    Post subject: Re: Sort Array Help! Reply with quote



At 21:27:13, 09.12.2005, Cenk wrote:

Quote:
#include #include using namespace std;

int main() {
int a[7] = {23, 1, 33, -20, 6, 6, 9};

sort(a, a+7);

for (int i=0; i<7; i++) {
cout << a[i] << " ";
}

return 0;
}

Works for me (BCB 2006). Produces:

-20 1 6 6 9 23 33

And that looks correct to me.

--
Rudy.Velthuis {TeamB} http://velthuis.homepage.t-online.de/

" The best way to predict the future is to invent it." -- Alan Kay

Back to top
Rudy Velthuis [TeamB]
Guest





PostPosted: Fri Dec 09, 2005 8:39 pm    Post subject: Re: Sort Array Help! Reply with quote



At 21:27:13, 09.12.2005, Cenk wrote:

Quote:
Hi,

Is there a library or a function to sort one or two dimentional (int or
double) arrays? i found the code below but it gave error!

If you mention an error, please always state what exactly the error was.
I didn't get any.

If <algorithm> could not be found, your app is either not a C++ console
app, or your include directory is not set up properly in the project
options. Or you are using a very old C++ compiler.
--
Rudy.Velthuis {TeamB} http://velthuis.homepage.t-online.de/

"Some editors are failed writers, but so are most writers."
- T. S. Eliot (1888-1965)

Back to top
Chris Uzdavinis (TeamB)
Guest





PostPosted: Fri Dec 09, 2005 9:58 pm    Post subject: Re: Sort Array Help! Reply with quote

"Cenk" <cenk1536 (AT) yahoo (DOT) com> writes:

Quote:
Hi,

Is there a library or a function to sort one or two dimentional (int
or double) arrays?

The standard library can sort 1 dimensional arrays. Perhaps you can
find a 3rd party library to do two dimensions.

Quote:
i found the code below but it gave error!

It does? What error?

Quote:
i think <algorithm> could not be recognized!

Did you get an error on <algorithm> or not?

Quote:
Please help.

Sure, what's the problem?

Quote:
#include #include using namespace std;

int main() {
int a[7] = {23, 1, 33, -20, 6, 6, 9};

sort(a, a+7);

for (int i=0; i<7; i++) {
cout << a[i] << " ";
}

return 0;
}

That's valid code, so you'll have to be clearer on what your
problem(s) actually are.

--
Chris (TeamB);

Back to top
Cenk
Guest





PostPosted: Sat Dec 10, 2005 4:52 pm    Post subject: [C++ Error] mainmovingavg.cpp(2576): E2268 Call to undefined Reply with quote

Here is what i get when i wanna use it

[C++ Error] mainmovingavg.cpp(2576): E2268 Call to undefined function 'sort'


"Chris Uzdavinis (TeamB)" <chris (AT) uzdavinis (DOT) com>, haber iletisinde sunlari
yazdi:j5irtyoru0.fsf (AT) explicit (DOT) atdesk.com...
Quote:
"Cenk" <cenk1536 (AT) yahoo (DOT) com> writes:

Hi,

Is there a library or a function to sort one or two dimentional (int
or double) arrays?

The standard library can sort 1 dimensional arrays. Perhaps you can
find a 3rd party library to do two dimensions.

i found the code below but it gave error!

It does? What error?

i think <algorithm> could not be recognized!

Did you get an error on <algorithm> or not?

Please help.

Sure, what's the problem?

#include #include using namespace std;

int main() {
int a[7] = {23, 1, 33, -20, 6, 6, 9};

sort(a, a+7);

for (int i=0; i<7; i++) {
cout << a[i] << " ";
}

return 0;
}

That's valid code, so you'll have to be clearer on what your
problem(s) actually are.

--
Chris (TeamB);



Back to top
Liz Albin
Guest





PostPosted: Sat Dec 10, 2005 5:40 pm    Post subject: Re: [C++ Error] mainmovingavg.cpp(2576): E2268 Call to undef Reply with quote

On Sat, 10 Dec 2005 18:52:22 +0200, Cenk wrote:

Quote:
Here is what i get when i wanna use it

[C++ Error] mainmovingavg.cpp(2576): E2268 Call to undefined function 'sort'

Is that your exact code? I ask because creating a new console app
with bcp 6 , and using this code I get success.

Are you /certain/ that you've got the "using" line?

//---------------------------------------------------------------------------

#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
#include <iostream>
#include <algorithm>
using namespace std;

int main(int argc, char* argv[])
{

int a[7] = {23, 1, 33, -20, 6, 6, 9};

sort(a, a+7);

for (int i=0; i<7; i++) {
cout << a[i] << " ";
}

return 0;
}
--
liz

Back to top
Cenk
Guest





PostPosted: Sun Dec 11, 2005 8:56 pm    Post subject: Re: [C++ Error] mainmovingavg.cpp(2576): E2268 Call to undef Reply with quote

well actually it is NOT my code, i just wanted 2 use "SORT" function! i
added #include<algorithm> and used the "SORT" function but i got this error!
"Liz Albin" <lizalbinNotThis (AT) yahoo (DOT) com>, haber iletisinde sunlari
yazdi:1f7hmz15urrl8.1q74r4lw03xxh.dlg (AT) 40tude (DOT) net...
Quote:
On Sat, 10 Dec 2005 18:52:22 +0200, Cenk wrote:

Here is what i get when i wanna use it

[C++ Error] mainmovingavg.cpp(2576): E2268 Call to undefined function
'sort'

Is that your exact code? I ask because creating a new console app
with bcp 6 , and using this code I get success.

Are you /certain/ that you've got the "using" line?

//---------------------------------------------------------------------------

#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
#include #include using namespace std;

int main(int argc, char* argv[])
{

int a[7] = {23, 1, 33, -20, 6, 6, 9};

sort(a, a+7);

for (int i=0; i<7; i++) {
cout << a[i] << " ";
}

return 0;
}
--
liz



Back to top
Rudy Velthuis [TeamB]
Guest





PostPosted: Sun Dec 11, 2005 9:07 pm    Post subject: Re: [C++ Error] mainmovingavg.cpp(2576): E2268 Call to undef Reply with quote

At 21:56:00, 11.12.2005, Cenk wrote:

Quote:
well actually it is NOT my code, i just wanted 2 use "SORT" function! i
added #include<algorithm> and used the "SORT" function but i got this
error!

If you did not specify

using namespace std;

then you'll have to specify the namespace explicitly (using std:Smile :

#include <iostream>
#include <algorithm>

int main()
{
int a[7] = {23, 1, 33, -20, 6, 6, 9};

std::sort(a, a+7);

for (int i = 0; i < 7; i++)
{
std::cout << a[i] << " ";
}

return 0;
}

Mayn people actually prefer that, since it does not throw an entire
namespace into the current code.
--
Rudy.Velthuis {TeamB} http://velthuis.homepage.t-online.de/

"If you can't get rid of the skeleton in your closet, you'd best teach it
to dance."
- George Bernard Shaw (1856-1950)

Back to top
Cenk
Guest





PostPosted: Sun Dec 11, 2005 9:15 pm    Post subject: Re: [C++ Error] mainmovingavg.cpp(2576): E2268 Call to undef Reply with quote

Thanks, but i need to know how to sort double arrays?
t_index is a double array.
std::sort(t_index,t_index+3);

"Rudy Velthuis [TeamB]" <velthuis (AT) gmail (DOT) com>, haber iletisinde sunlari
yazdi:xn0eavief5lokok00e-velthuis (AT) www (DOT) teamb.com...
Quote:
At 21:56:00, 11.12.2005, Cenk wrote:

well actually it is NOT my code, i just wanted 2 use "SORT" function! i
added #include<algorithm> and used the "SORT" function but i got this
error!

If you did not specify

using namespace std;

then you'll have to specify the namespace explicitly (using std:Smile :

#include #include
int main()
{
int a[7] = {23, 1, 33, -20, 6, 6, 9};

std::sort(a, a+7);

for (int i = 0; i < 7; i++)
{
std::cout << a[i] << " ";
}

return 0;
}

Mayn people actually prefer that, since it does not throw an entire
namespace into the current code.
--
Rudy.Velthuis {TeamB} http://velthuis.homepage.t-online.de/

"If you can't get rid of the skeleton in your closet, you'd best teach it
to dance."
- George Bernard Shaw (1856-1950)



Back to top
Cenk
Guest





PostPosted: Sun Dec 11, 2005 9:18 pm    Post subject: Re: [C++ Error] mainmovingavg.cpp(2576): E2268 Call to undef Reply with quote

And its also DynamicArray !

"Cenk" <cenk1536 (AT) yahoo (DOT) com>, haber iletisinde şunları
yazdı:439c96ba (AT) newsgroups (DOT) borland.com...
Quote:
Thanks, but i need to know how to sort double arrays?
t_index is a double array.
std::sort(t_index,t_index+3);

"Rudy Velthuis [TeamB]" <velthuis (AT) gmail (DOT) com>, haber iletisinde sunlari
yazdi:xn0eavief5lokok00e-velthuis (AT) www (DOT) teamb.com...
At 21:56:00, 11.12.2005, Cenk wrote:

well actually it is NOT my code, i just wanted 2 use "SORT" function! i
added #include<algorithm> and used the "SORT" function but i got this
error!

If you did not specify

using namespace std;

then you'll have to specify the namespace explicitly (using std:Smile :

#include #include
int main()
{
int a[7] = {23, 1, 33, -20, 6, 6, 9};

std::sort(a, a+7);

for (int i = 0; i < 7; i++)
{
std::cout << a[i] << " ";
}

return 0;
}

Mayn people actually prefer that, since it does not throw an entire
namespace into the current code.
--
Rudy.Velthuis {TeamB} http://velthuis.homepage.t-online.de/

"If you can't get rid of the skeleton in your closet, you'd best teach it
to dance."
- George Bernard Shaw (1856-1950)





Back to top
Thomas Maeder [TeamB]
Guest





PostPosted: Sun Dec 11, 2005 9:31 pm    Post subject: Re: [C++ Error] mainmovingavg.cpp(2576): E2268 Call to undef Reply with quote

"Cenk" <cenk1536 (AT) yahoo (DOT) com> writes:

Quote:
Thanks, but i need to know how to sort double arrays?
t_index is a double array.
std::sort(t_index,t_index+3);

This is how it should work:

#include <algorithm>

int main()
{
double array[3] = { 1.0, 2.0, 0.0 };
std::sort(array,array+3);
}


If it doesn't work: *how* doesn't it work?


And please read a good C++ text book; std::sort() is documented in
each of them. To find a good C++ text book, read the reviews at
http://www.accu.org/

Back to top
Thomas Maeder [TeamB]
Guest





PostPosted: Sun Dec 11, 2005 9:32 pm    Post subject: Re: [C++ Error] mainmovingavg.cpp(2576): E2268 Call to undef Reply with quote


Please direct your browser at http://info.borland.com/newsgroups/ and
read the newsgroup guidelines. One of them asks us not to quote entire
posts we are following up to; instead, please trim the quotes to the
parts relevant for your reply. Thanks!


"Cenk" <cenk1536 (AT) yahoo (DOT) com> writes:

Quote:
And its also DynamicArray !

What is this statement supposed to mean?

Back to top
Rudy Velthuis [TeamB]
Guest





PostPosted: Sun Dec 11, 2005 9:33 pm    Post subject: Re: [C++ Error] mainmovingavg.cpp(2576): E2268 Call to undef Reply with quote

At 22:15:30, 11.12.2005, Cenk wrote:

Quote:
Thanks, but i need to know how to sort double arrays?
t_index is a double array.
std::sort(t_index,t_index+3);

The same way (that is the beauty of templates, they can be applied on
different types):

#include <iostream>
#include <algorithm>

int main(int, char**)
{
double t_index[] = {3.0, 1.3, 2.7};

std::sort(t_index, t_index + 3);

for (int i = 0; i < 3; i++)
{
std::cout << t_index[i] << " ";
}

std::cin.get(); // wait for keypress before closing console window
return 0;
}

Produces:

1.3 2.7 3



--
Rudy.Velthuis {TeamB} http://velthuis.homepage.t-online.de/

"I criticize by creation - not by finding fault." -- Cicero (106-43 B.C.)

Back to top
Rudy Velthuis [TeamB]
Guest





PostPosted: Sun Dec 11, 2005 10:05 pm    Post subject: Re: [C++ Error] mainmovingavg.cpp(2576): E2268 Call to undef Reply with quote

At 22:18:23, 11.12.2005, Cenk wrote:

Quote:
And its also DynamicArray !

Then it is not a normal array.

In that case, you use

std::sort(&t_index[0], &t_index[2] + 1);

You can not use &t_index[3] as second parameter, since that is not a
defined index. Dynamic arrays are bounds checked.

#include <vcl.h>
#include <iostream>
#include <algorithm>

int main(int, char**)
{
DynamicArray<double> t_index;

t_index.set_length(3);

t_index[0] = 3.1;
t_index[1] = 1.3;
t_index[2] = 2.7;

std::sort(&t_index[0], &t_index[2] + 1);

for (int i = 0; i < 3; i++)
{
std::cout << t_index[i] << " ";
}

std::cin.get();
return 0;
}

BTW, why don't you use std::vector STL, just like sort(), and has special functions returning iterators
sort() can use:

#include <iostream>
#include <vector>
#include <algorithm>

int main(int, char**)
{
std::vector<double> v(3);

v[0] = 3.1;
v[1] = 1.3;
v[2] = 2.7;

std::sort(v.begin(), v.end());

for (int i = 0; i < 3; i++)
{
std::cout << v[i] << " ";
}

std::cin.get();

return 0;
}

--
Rudy.Velthuis {TeamB} http://velthuis.homepage.t-online.de/

"It's not the size of the dog in the fight, it's the size of the fight
in the dog."
- Mark Twain (1835-1910)

Back to top
Cenk
Guest





PostPosted: Sun Dec 11, 2005 10:15 pm    Post subject: Re: [C++ Error] mainmovingavg.cpp(2576): E2268 Call to undef Reply with quote

THANKS so much
"Rudy Velthuis [TeamB]" <velthuis (AT) gmail (DOT) com>, haber iletisinde sunlari
yazdi:xn0eavjxu5nrn0600g-velthuis (AT) www (DOT) teamb.com...
Quote:
At 22:18:23, 11.12.2005, Cenk wrote:

And its also DynamicArray !

Then it is not a normal array.

In that case, you use

std::sort(&t_index[0], &t_index[2] + 1);

You can not use &t_index[3] as second parameter, since that is not a
defined index. Dynamic arrays are bounds checked.

#include <vcl.h
#include #include
int main(int, char**)
{
DynamicArray
t_index.set_length(3);

t_index[0] = 3.1;
t_index[1] = 1.3;
t_index[2] = 2.7;

std::sort(&t_index[0], &t_index[2] + 1);

for (int i = 0; i < 3; i++)
{
std::cout << t_index[i] << " ";
}

std::cin.get();
return 0;
}

BTW, why don't you use std::vector STL, just like sort(), and has special functions returning iterators
sort() can use:

#include <iostream
#include #include
int main(int, char**)
{
std::vector
v[0] = 3.1;
v[1] = 1.3;
v[2] = 2.7;

std::sort(v.begin(), v.end());

for (int i = 0; i < 3; i++)
{
std::cout << v[i] << " ";
}

std::cin.get();

return 0;
}

--
Rudy.Velthuis {TeamB} http://velthuis.homepage.t-online.de/

"It's not the size of the dog in the fight, it's the size of the fight
in the dog."
- Mark Twain (1835-1910)



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.