388 Posted Topics

Member Avatar for seanbp

[CODE] int* array_end = array_begin; for (register int i = 0; i < len; i++) array_end++; [/CODE] This is a pointlessly roundabout (and slow) way of writing [CODE] int* array_end = array_begin + len; [/CODE] More generally, what is the point in posting a bubble sort that works only on …

Member Avatar for seanbp
0
377
Member Avatar for mbouster

Please post the code you have written so far, and explain what problems you having in getting it to work.

Member Avatar for mbouster
0
131
Member Avatar for astala27

OK, you don't get the parentheses part. So how about writing a program to do the rest of it and posting it when you're done? If you do that, I'm sure someone will give you a hint about how to do the rest of it. As it is, you're just …

Member Avatar for arkoenig
0
2K
Member Avatar for BigDeveloper

The first function is riddled with errors: 1) It is missing two right curly braces. 2) Its parameter is named h but the body of the function uses an otherwise undefined variable named head. 3) The loop goes through only one iteration. 4) The code compares the pointer named current …

Member Avatar for BigDeveloper
0
118
Member Avatar for dynamyt3

Take each element of your array in turn, and swap it with a randomly chosen element with a position that is >= the one you're swapping. Note that this raises the possibility that an element may be swapped with itself; if it is, that's equivalent to leaving that element alone. …

Member Avatar for dynamyt3
0
1K
Member Avatar for OrangeGrover

I see nothing technically wrong with the original code, which suggests that the problem is elsewhere. However, the code is unnecessarily complicated and can also be very slow if the DetectedFaces vector is large. Moreover, it destroys the DetectedFaces vector, which may or may not be what you want. A …

Member Avatar for OrangeGrover
0
320
Member Avatar for Awais Ali mugha

I will ask some questions that should help you solve your problem--if you answer them. Here are the first three questions: 1) How many different moves are possible from the starting position? 2) Once you have made the first move, how many different moves are possible from the position that …

Member Avatar for arkoenig
-4
91
Member Avatar for alexchen

You're doing a division in line 8. Can you prove that the divisor is never zero?

Member Avatar for Fbody
0
165
Member Avatar for harryhaaren

Before you spend too much time trying to find faster ways of copying vectors, you might give some thought to whether (and, if so, why) copying is a significant part of your program's total execution time. After all, if you're copying a vector, presumably you need two copies, so you're …

Member Avatar for Narue
0
4K
Member Avatar for moni94

If the "if" statement that is the subject of the else in line 9 yields true in its test, then the function falls off the end without executing a return statement. The value that the function returns in that case is undefined.

Member Avatar for moni94
0
204
Member Avatar for flasp

I could tell you that functional programming (FP) is a style of programming in which one never changes a value that has already been computed. Instead, one creates new values as needed. By implication, using FP in practice requires a good garbage collector in order to get rid of values …

Member Avatar for flasp
0
145
Member Avatar for jcax

There was an extended debate in the C++ standards committee about whether the standard library should be required to support recursive data structures. The simplest case: [CODE] struct T { vector<T> vt; }; [/CODE] There is no technical reason why this should not be possible, but implementing it is quite …

Member Avatar for jcax
0
132
Member Avatar for alexchen
Member Avatar for blah32

How about posting your compare function? That seems to me to be the most likely cause of the problem.

Member Avatar for arkoenig
0
113
Member Avatar for BrianTurkish

Why are you bothering to write your own sort instead of using std::stable_sort?

Member Avatar for ravenous
0
155
Member Avatar for Holy_Roller

Why not define a third parameter to your addMap function: [CODE] // I changed the return type to void because you don't use the return value void addMap(strMap& mymap, string Fname, string Lname) { // where Fname and Lname are strings entered by the user // in main that hold …

Member Avatar for Holy_Roller
0
100
Member Avatar for kleorix
Member Avatar for blah32

Sets are ordered based on the comparison function that you supply. So when you call upper_bound, what you get is an iterator referring to a position in the set that is based on calling the comparison function. If your comparison function compares based on a member variable, then that's what …

Member Avatar for arkoenig
0
219
Member Avatar for puretnaant

Line 27 of your original code sets the variable sizeA to 0. Line 30 calls the function getarrays, passing a reference to sizeA. Nowhere in the getarrays function do I see any code that ever changes the value of sizeA. So on return from getarrays, sizeA is still 0. I …

Member Avatar for misfit956
0
171
Member Avatar for MrJNV

I think you'd be better off learning to understand Euclid's Algorithm. You might try looking [URL="http://en.wikipedia.org/wiki/Euclid_algorithm"]here[/URL].

Member Avatar for arkoenig
0
606
Member Avatar for SoftwareGuy

OK, here's a trick. The hard part, as you will see, is figuring out how to unify the comparisons--i.e., to make the comparisons the same for each loop. So let's start in that direction by changing the comparison to inequality comparisons: [CODE] if (flag) for (i = 0; i != …

Member Avatar for SoftwareGuy
0
199
Member Avatar for kevintse

1. I see nothing wrong with your code. 2. Yes. 3. It's up to the compiler whether a1 and a2 share the same string constant.

Member Avatar for kevintse
0
129
Member Avatar for ShawnCplus

[QUOTE=mcldev;416889]Compared to swapping by using 3 variables, this is akin to MOV operations on the processor which are generally more expensive than XOR operations. [/QUOTE] Really? Why do you think so? An assignment requires one fetch and one store. An XOR requires two fetches, one store, and the XOR operation …

Member Avatar for arkoenig
0
232
Member Avatar for digan

The easiest way to improve it is to throw it out and use the queue implementation from the standard library. Why reinvent the wheel? If your purpose in writing this code is as an exercise, rather than to do something that you intend to be useful, then I don't understand …

Member Avatar for arkoenig
0
96
Member Avatar for tech9x

The code you posted cannot possibly compile for several reasons, including: 1) You never defined the variables n or price2. 2) The variables price and price2 do not have definitions in scope in the functions apple and orange. If you post code that does not compile, and you complain that …

Member Avatar for tech9x
0
145
Member Avatar for baldwindc
Member Avatar for arkoenig
0
1K
Member Avatar for Ninjah

In order to get a \ character into a string, or to write one as a char literal, you need to put two consecutive \ characters as part of your program between quotes. Examples: [CODE] char c; c = ''; // Wrong. c = '\'; // Right -- c now …

Member Avatar for Fbody
0
5K
Member Avatar for gpjacks

[QUOTE=thelamb;1393745]Your vector 'quantity' is uninitialized, which means you are trying to print garbage. [/QUOTE] Not true. If you create a vector of integers and do not initislize it, the integers are initialized to 0. More generally, if you create a vector of objects of type T, the initialization process creates …

Member Avatar for gpjacks
0
266
Member Avatar for ayesha91

When you execute int *intersection = new int[inter]; and then you change the value of inter, that does not change the number of elements in the block of memory to which intersection points. That is exactly the assumption you are making in lines 5 and 14, respectively, of the third …

Member Avatar for dwks
0
169
Member Avatar for dinners

Don't do it -- it's a local extension and not part of C++. Do this instead: [code] int corners; cout << "Please enter the number of corners: "; cin >> corners; vector<int> x(corners); // Note: parentheses, not square brackets [/code] You have to say [code] #include <vector> [/code] for this …

Member Avatar for dinners
0
163
Member Avatar for lagvino_els
Member Avatar for Narue
0
104
Member Avatar for aaronmk2
Member Avatar for vavazoom
Member Avatar for vavazoom
0
276
Member Avatar for tKc

First you need to explain what you expect the code to do. Line 13 attempts to assign a value to a[count], but neither a nor count is defined anywhere. Without a hint as to what you expect that statement to do, it is hard to figure out how to get …

Member Avatar for Tellalca
0
155
Member Avatar for amoony

Show us what you have so far and explain what kind of difficulty you're having, and maybe someone will help.

Member Avatar for amoony
0
872
Member Avatar for dvspinay

Two suggestions: 1) Learn how to use code tags; without them, your code is very hard to read. 2) Pick [I]one[/I] function from the collection of functions described in your assignment and implement that. Post your implementation.

Member Avatar for arkoenig
0
130
Member Avatar for barevhayerable

The technique that jonsca describes is widely used, and I'll bet that most of the people who use it fail to realize that it doesn't quite work: The numbers yielded by rand()%n are not uniformly distributed unless n is an exact divisor of RAND_MAX+1. I believe that if n is …

Member Avatar for arkoenig
0
351
Member Avatar for awais1a
Member Avatar for mrnutty

[QUOTE=firstPerson;1390448]It definitely can be done in linear time, just because of its special nature, that is because of the properties, 1,2,3,4 listed above.[/QUOTE] Indeed. I had figured that the reason that no one bothered to answer it was that it was so easy. However, since no one has made any …

Member Avatar for arkoenig
0
102
Member Avatar for tagazin

Your program starts with a do...while loop that looks at the value of a variable named "choice" as its terminating condition. After that, you have a collection of if statements that also look at the value of this variable. However, I can find no place in your program where you …

Member Avatar for tagazin
0
363
Member Avatar for phoenix1095

If you're just getting started with C++, then the following advice may seem heretical; but long experience has convinced me that it is sound: Don't use arrays. Use vectors (i.e. std::vector<T>) instead. The reason is that arrays aren't really objects, which means that there are various restrictions on how you …

Member Avatar for arkoenig
0
187
Member Avatar for arunapad

In order for Map to work correctly, you have to give it a comparison function that acts like <, in the sense that it is nonreflexive, antisymmetric, and transitive. Your vectComp::operator() does not work that way. I do not need to read much of the code to determine this, because …

Member Avatar for arkoenig
0
336
Member Avatar for gunbuster363

[QUOTE=gunbuster363;1388736]New programming language like python and ruby, do they have space to grow?[/QUOTE] New? Python? It's about 20 years old! Heck, Python 2.0 is more than 10 years old...

Member Avatar for convoluted
0
309
Member Avatar for Gribouillis

I don't understand -- what aspect of the program's behavior are you proposing to change, and in what way?

Member Avatar for Gribouillis
0
599
Member Avatar for fuzmaster

Are you saying that you don't have the time to do your own homework but you want someone else to find the time to do it for you?

Member Avatar for arkoenig
-1
324
Member Avatar for lauruskamj
Member Avatar for mike_2000_17
0
99
Member Avatar for merse

If your computer supports IEEE floating-point, as most processors do, the five fundamental operations + - * / and sqrt will yield the correctly rounded result.

Member Avatar for merse
0
237
Member Avatar for joy55

In order to solve a problem successfully, you must first understand what it is. One way to test your understanding is to solve a simple version of it by hand, without using a computer. So... m = 13, n = 241. In other words, what is the base-13 representation of …

Member Avatar for maria198
0
170
Member Avatar for hondros

Your problem is probably that your program is trying to remove blanks in place, but on line 50 you're calling it with a string literal as its arguments. Compilers are permitted to write-protect the contents of string literals, and many of them do these days. As a quick check of …

Member Avatar for VernonDozier
0
207
Member Avatar for merse

C++ does not require that, but the IEEE floating-point standard does. So if you're using C++ on an IEEE-conforming machine, it will behave as you want; otherwise you get what you get.

Member Avatar for Ancient Dragon
0
95

The End.