388 Posted Topics
Re: [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 … | |
Re: Please post the code you have written so far, and explain what problems you having in getting it to work. | |
Re: 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 … | |
Re: 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 … | |
Re: 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. … | |
Re: 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 … | |
Re: 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 … | |
Re: You're doing a division in line 8. Can you prove that the divisor is never zero? | |
Re: 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 … | |
Re: 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. | |
Re: 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 … | |
Re: 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 … | |
Re: How about posting your compare function? That seems to me to be the most likely cause of the problem. | |
Re: Why are you bothering to write your own sort instead of using std::stable_sort? | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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]. | |
Re: 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 != … | |
Re: 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. | |
Re: [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 … | |
Re: 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 … | |
Re: 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 … | |
Re: What do you think the expression country_name[i][20] means? | |
Re: 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 … | |
Re: [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 … | |
Re: 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 … | |
Re: 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 … | |
Re: Here you go: [url]http://en.wikipedia.org/wiki/AA_tree[/url] | |
| |
Re: Make a random integer between 50 and 99999, then divide it by 100.0 | |
Re: 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 … | |
Re: Show us what you have so far and explain what kind of difficulty you're having, and maybe someone will help. | |
![]() | Re: 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. |
Re: 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 … | |
Re: If this is the biggest problem of your life, you are truly blessed. | |
Re: [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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: [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... | |
Re: I don't understand -- what aspect of the program's behavior are you proposing to change, and in what way? | |
Re: 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? | |
Re: If your computer supports IEEE floating-point, as most processors do, the five fundamental operations + - * / and sqrt will yield the correctly rounded result. | |
Re: 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 … | |
Re: 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 … | |
Re: 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. |
The End.