388 Posted Topics

Member Avatar for wittykitty

Where do you remove elements from the list? I see that you call deleteNode(data), but you haven't shown us what deleteNode does.

Member Avatar for Lerner
0
134
Member Avatar for guyfrompluto

What the OP described is a variation of the [URL="http://en.wikipedia.org/wiki/Knapsack_problem"]Knapsack Problem[/URL], which is NP-complete (i.e. known to be very difficult from a computational viewpoint).

Member Avatar for Beat_Slayer
0
706
Member Avatar for ashu2401

If the array is sorted, the problem is easy to solve in O(n). Start with a pair of pointers (or indices) at opposite ends of the array. Step one of the pointers through the array one element at a time. For each element, step the other pointer [I]backward[/I] through the …

Member Avatar for arkoenig
0
329
Member Avatar for jrw89

Once your program has reached end of file, it is no longer possible to read any more input. So if you enter end of file after reading the last student's name, it is not possible to read the grades. The intent of the exercise was for each student's name to …

Member Avatar for mrnutty
0
191
Member Avatar for evilsithgirl

If memory has 16K blocks of 8 bytes each, what does that say about the possible values that memory addresses can have?

Member Avatar for arkoenig
0
80
Member Avatar for hui_yang

@tuff: I think that your statement solves the letter of the problem but violates its spirit. That is, I think the point of the original question was to understand which recursive functions could be turned into tail-recursive functions that in turn can be turned into iterative functions that require an …

Member Avatar for arkoenig
0
128
Member Avatar for Sinaru

Instead of [CODE]return (static_cast<Person>(*this) == static_cast<Person>(right));[/CODE] you should write [CODE]return (*static_cast<Person*>(this) == *static_cast<Person*>(&right));[/CODE] because otherwise you are asking the compiler to generate code that copies the objects "right" and "*this".

Member Avatar for arkoenig
0
169
Member Avatar for tron_thomas
Member Avatar for frogboy77
Member Avatar for arkoenig
0
103
Member Avatar for AutoC

[ICODE]s.substr(0,p)[/ICODE] The first argument is the starting position; the second is the length. If you omit the length, you get the longest possible substring with the given starting position, which is why [icode]s.substr(p+1)[/icode] works.

Member Avatar for AutoC
0
251
Member Avatar for The_Prince

Here's one way. You'll have to translate my prose into code. 1) Start with a sequence of 0 bits. 2) Repeat steps 3-5 until the sequence is all 1-bits. 3) Locate the leftmost 0 bit. (This works because the sequence is known not to be all 1-bits) 4) Set that …

Member Avatar for Lerner
0
112
Member Avatar for psalmmie
Re: Mr

[URL="http://www.youtube.com/watch?v=toiM1B6E2ww"]Click here.[/URL]

Member Avatar for arkoenig
0
67
Member Avatar for James0l9l

Your loop says [icode]for x in range(50):[/icode], so it will execute 50 times. You want to create a 50 by 50 grid, so you want it to have 2500 entries. How can you expect to create a data structure with 2500 entries if your loop executes only 50 times?

Member Avatar for griswolf
0
261
Member Avatar for gerard4143

I'm biased, of course; but I think that [I]Accelerated C++[/I] is pretty close to what you're looking for; it definitely has a tutorial narrative, so it's intended to be read sequentially (unlike many that are essentially reference books) and it covers quite a bit more material than most introductory books.

Member Avatar for DAlexNagy
0
232
Member Avatar for Kanoisa

Using the standard list.sort algorithm should not take several seconds to sort a few hundred elements, so something must be wrong. Unfortunately, I can't read the file you attached. When I try, I get "invalid or corrupted" So perhaps you could post the relevant portions of the code, particularly your …

Member Avatar for Kanoisa
0
326
Member Avatar for pwnmercury

[QUOTE=vegaseat;1319267]Switch/case is rather slow in C or C++ and therefore was not implemented in Python.[/QUOTE] Switch/case is slow in C or C++? Not in my experience. Do you have evidence to support this claim?

Member Avatar for vegaseat
0
236
Member Avatar for therobot

The "for each" statement isn't part of standard C++, so I'm not familiar with its exact semantics. However, I would expect that it would have to work by making [icode]comp[/icode] a copy of each element in turn of [icode]sysRelMap[/icode]. The reason is simple: If it didn't make a copy, what …

Member Avatar for arkoenig
0
138
Member Avatar for ichigo_cool

[icode]overwriteSlot < 1 && overwriteSlot > 3[/icode] is always false, because no value can be less than 1 and greater than 3 at the same time. So your loop will never terminate. I am guessing that you meant to write || rather than &&.

Member Avatar for ichigo_cool
0
111
Member Avatar for coolboss
Re: hii

If you write a loop that runs backward through an array, it is a good idea to get into the habit of decrementing the control variable at the [I]beginning[/I] of the loop: [code] int pro[100]; for (int a = 100; a > 0;) { --a; // whatever } [/code] This …

Member Avatar for arkoenig
0
117
Member Avatar for newbie_to_cpp

Most of the programmers I know--but by no means all of them--are male. I think that reflects interest much more than it reflects talent or aptitude. For that matter, I've seen some spectacularly bad male programmers as well.

Member Avatar for NicAx64
0
110
Member Avatar for pdk123

If you want your program to be reliable, I suggest you look for a different way of solving your problem. You have a pointer to one type (uint8) and you casted it to a pointer to a different type (A). Compilers are under no obligation to make such a cast …

Member Avatar for pdk123
0
142
Member Avatar for Stefano Mtangoo

What do you want to happen when you do this? [code] SecondChild sc; sc.setResults("foo"); [/code] and how do you want what happens to differ from what happens when you do this? [code] BaseDB b; b.setResults("foo"); [/code] In both cases, you're trying to call a member function that isn't defined.

Member Avatar for Stefano Mtangoo
0
130
Member Avatar for group256

[QUOTE=mike_2000_17;1316517]Well, you can use the std::sort algorithm in "#include <algorithm>". The only little problem is that it cannot be used with a list because [URL="http://www.cplusplus.com/reference/stl/list/"]list[/URL] provides only [URL="http://www.cplusplus.com/reference/std/iterator/BidirectionalIterator/"]bidirectional iterators[/URL], not [URL="http://www.cplusplus.com/reference/std/iterator/RandomAccessIterator/"]random access iterators[/URL], which is required for the [URL="http://www.cplusplus.com/reference/algorithm/sort/"]sort algorithm[/URL]. [/QUOTE] The standard list class has its own sort member …

Member Avatar for mrnutty
0
5K
Member Avatar for effizy

There is only one way to learn to write programs, and that is by writing programs. Just get out there and do it. If you can, work on stuff that you personally find interesting; but writing programs that bore you will still teach you more than not programming at all.

Member Avatar for Jackk123
0
139
Member Avatar for abysss

The current C++ standard does not support threads, so you will either have to pick a nonstandard implementation or wait until the new standard is complete.

Member Avatar for abysss
0
145
Member Avatar for pspwxp fan

[QUOTE=embooglement;1316052]The line "car * autocar = new car[count];" makes an array of cars of size count, and autocar is a pointer to that array.[/QUOTE] Not quite: autocar is a pointer to the initial element of the array, not a pointer to the array. This distinction is important because it means …

Member Avatar for embooglement
0
136
Member Avatar for darkroad

[QUOTE=Ancient Dragon;1315193]Well, you would be doing it wrong. There is no need to hard code the number of digits. [code] int sumdigits(int n) { int sum = 0; while( n > 0) { sum += (n%10); n /= 10; } return sum; } [/code][/QUOTE] This program doesn't quite solve the …

Member Avatar for ananda2007
0
168
Member Avatar for badboy11
Member Avatar for EdAtTheAirport

What I don't understand is why a book that purports to teach C++ spends so much effort on what is effectively a C program. Isn't it easier to understand this? [code] // read the first string string s1; cout << "Enter string #1: "; getline(cin, s1); // now the second …

Member Avatar for arkoenig
0
202
Member Avatar for yapkm01

[QUOTE=yapkm01;1315161]C++ Primer 4th edition says default constructor is used regardless where a class variable is declared - does that means variable of class type is initialized whether it is global or local?[/QUOTE] Yes, that's what it means, as long as the class has one or more constructors. Even if the …

Member Avatar for arkoenig
0
1K
Member Avatar for dadam88
Member Avatar for Fbody
0
274
Member Avatar for pdk123

[QUOTE=pdk123;1304231]As you suggested if i use the prgma_pack for these structures, i donot need to worry at all... [/QUOTE] If you use [I]any[/I] pragma, you [I]always[/I] need to worry. Pragma has two properties that is guaranteed to cause worry: 1) The very nature of pragma is machine-dependent. 2) An implementation …

Member Avatar for mike_2000_17
0
162
Member Avatar for gaurav_13191

The first statements you execute in your main program are [CODE] p = NULL; add(&p,5); [/CODE] The first statements you execute in add are [CODE] r=*q; if(num<=r->data||r==NULL) // ... [/CODE] Here, q is the first parameter of add, which means that the value of q is &p as computed in …

Member Avatar for arkoenig
0
110
Member Avatar for miturian

[QUOTE=miturian;1304080]So, what is puzzling me here is how the length can be shorther than the amount of elements in the vector? I thought it was supposed to resize automatically?[/QUOTE] You thought wrong. The size of a vector changes only if you do something that changes it. Assigning a value to …

Member Avatar for arkoenig
0
185
Member Avatar for potato4610

Line 16 compares the values of the two pointers, not the values of the doubles to which they point. Also, if your argument is const double *, that means you're promising not to change the value to which the pointer points. If you now return double *, you're violating that …

Member Avatar for dusktreader
0
310
Member Avatar for hazar

[QUOTE=hazar;1295177]What is to stop someone simply 'going backwards' in terms of the encryption process, for example if I encrypt something using a public key why can't I simply decrypt it using the same public key? [/QUOTE] The simplest answer is that if it were possible to do that, what you …

Member Avatar for hazar
0
161
Member Avatar for wizrad
Member Avatar for Fbody
0
267
Member Avatar for magician89

Please show us the work you've done so far, and explain where you're stuck.

Member Avatar for aman rathi
0
153
Member Avatar for el33t

Every derived-class object contains a base-class object as part of it. By implication, constructing a derived-class object involves constructing the base-class object as well. Therefore, when you construct an object of type Bar, part of that construction process is to construct an object of type Foo. The Foo constructor is …

Member Avatar for caut_baia
0
197
Member Avatar for jwxie

Are you saying that you'd like a programmer to be able to write 14 and have it mean, say, 42? That's what changing a literal constant would mean.

Member Avatar for jwxie
0
98
Member Avatar for fr0styh3rb

This is a Java program; I think you will be more likely to get help with it if you post it in a Java forum rather than a C++ forum.

Member Avatar for arkoenig
0
120
Member Avatar for Garrett2011

The reason is that it is difficult to implement nested functions in a way that maintains compatibility with C and other compilers. For example: [code] extern void f(void (*)()); int main() { int x; void g() { x = 42; } f(g); } [/code] In order for this program to …

Member Avatar for arkoenig
0
533
Member Avatar for dadam88

The expression [icode]pick != 'r' || pick != 'g'[/icode] is always true. The reason is that either [icode]pick != 'r'[/icode] is true, in which case the whole expression is true, or [icode]pick != 'r'[/icode] is false, in which case pick must be equal to 'r'. And if that is the …

Member Avatar for arkoenig
0
94
Member Avatar for sabareesh

Also, the form of your example: [CODE] String operator+(const String &s) [/CODE] suggests that [icode]operator+[/icode] is a member function. The name of the class, [icode]String[/icode], suggests that [icode]operator+[/icode] is probably being used for concatenation. The fact that the function has one argument rather than two suggests that it is probably …

Member Avatar for sabareesh
0
181
Member Avatar for reolynda

I beg to differ with both of the previous posters. Most computers these days (including, so far as I know, all currently manufactured Intel processors) use IEEE floating point, which requires that the results of floating-point addition, subtraction, multiplication, division, and square root be deterministic. In particular, the IEEE standard …

Member Avatar for reolynda
0
97
Member Avatar for coolmel55

Assuming that the actual question meant to ask whether each element of one array is equal to the corresponding element of the other, the first observation is that in order for them to be equal, they must have the same number of elements, which I'll call [icode]n[/icode]. Then [code] std::equal(array1, …

Member Avatar for arkoenig
0
306
Member Avatar for wyssen

Note that the value returned by [icode]ip.c_str()[/icode] persists only until the next time you change the value of [icode]ip[/icode]. So if you modify [icode]ip[/icode] in any way between the time you assign the value to argv[1] and the time you use the value, the effect is undefined.

Member Avatar for wyssen
0
282
Member Avatar for Twinzen

You should write[icode]iter!=fg_sprites.end()[/icode] rather than [icode]iter<fg_sprites.end()[/icode] because the multiset type offers a bidirectional iterator, not a random-access iterator, and only random-access iterators support <. (also, it is preferable to write [icode]++iter[/icode] rather than [icode]iter++[/icode] because there's no need to copy the value of [icode]iter[/icode] and then throw the copy away …

Member Avatar for Twinzen
0
141
Member Avatar for Kanoisa

Your statement [CODE] Write = &WriteLogS; [/CODE] should be [CODE] Write = &Logger::WriteLogS; [/CODE] and similarly for the other similar statement.

Member Avatar for Kanoisa
0
194
Member Avatar for figuer25

I'd like to echo Aranarth's comments. In addition: 1) The clear() function appears to delete one element, despite the comment that suggests that it deletes all of them. 2) Therefore, the destructor deletes one element and leaves the rest of them sitting around. 3) You have no copy constructor or …

Member Avatar for figuer25
0
404

The End.