Rashakil Fol 978 Super Senior Demiposter Team Colleague

Yeah, its efficiency is proportional to its distance from the end.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

First of all, you passed p_beginning to the function and then tried to use k_beginning. Your code compiles?

Second, you expect us to have a crystal ball that can read your mind. What does "add_before_element" mean? Do you want to add before the element containing 'number'? Or do you want to add before the numberth element? Without explaining at all what find_element tries to do, this is still unknown.

And how in the world do you expect to insert the number 42 before the element either containing 2 or lying at the second position, using a function that gets passed only one integer?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

If you want to delete only one offset, use only one iterator.

vector<int> v;
for (i = 0; i < 10; ++i) {
    v.push_back(i);
}

v.erase(v.begin() + 7);

for (i = 0; i < v.size(); ++i) {
    cout << v[i] << endl;
}

Output:

0
1
2
3
4
5
6
8
9

See cppreference.com if you want more info on how erase() works.

Dave Sinkula commented: Haven't I given you rep yet? You've surely earned more than this. +3
Rashakil Fol 978 Super Senior Demiposter Team Colleague

To remove the nth element, just use begin() + n as the iterator.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

You need to use server side code. Whatever processes the form should check for this.

Using Javascript can save the user some time, so that's good, too, but the code on the server that processes the form shouldn't assume that it has valid input.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Suppose you have the scrambled string, "urcoppnei".

You want to be able to quickly go from scrambled string to unscrambled. How?

Sort the letters of the string in increasing order. That gives us "ceinoppru".

Now take every word in the dictionary, and sort their letters in increasing order. Put this in a hash, where the sorted form is the key and a list of words is the value. (Use a list, not a single word, because anagrams have the same sorted form. For example, the key "dgino" would have as its value a list containing both "doing" and "dingo".)

Once you do that, look up "ceinoppru" in the hash. You'll probably find that the key "ceinoppru" maps to a list containing one element, "porcupine".

Of course, it would be better to have your dictionary file in the format

...
aaardkrv aardvark
...
dgino doing dingo
...

It wouldn't hurt to sort it by the letter-sorted key.

So, you would unscramble by sorting the letters of the word in ascending order, by looking for this result in the text file (or hash, or map, or whatever).

I don't really understand your file format -- it looks like it's listing words with subwords. Why?

And here's a second edit. What you are asking and your sample input and output seem to be on completely different topics! You leave me baffled...

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Are you looking to use a program that edits text solely from the command line?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

[edit]You need to iterate, but if you make a simple function that does this, using that function is not such a big deal.[/edit]

If you need to grab the minimum and maximum values very frequently, these ideas might be helpful:

The following works well if you only insert elements into the map, and don't remove them.

Make something along the lines of

class minmaxvaluemap {
    map<typea, typeb> m_;
    map<typea, typeb>::iterator min_, max_;
};

with useful member functions.

And then update the min_ and max_ iterators to point to the pair with the minimum and maximum element every time you insert an element into the map.

If you needed to remove an element, that would be inefficient, though, because then you'd need to iterate through the entire map. So if you're adding and removing elements constantly, this would not be a good solution.

If you need to remove elements and still keep track of the minimum and maximum, use two maps in parallel -- one (map A) that maps strings to numbers and one (map B) that maps numbers to strings. (This is obviously not superbly memory-efficient, but it's only off from optimal by a pretty small scalar factor.) If the strings tend to be pretty large, you might want to have B pair numbers with map<number,string> iterators, iterators that point into A. Actually, you would probably want to do this in all cases.

Then, you just need to make sure you keep …

Rashakil Fol 978 Super Senior Demiposter Team Colleague

myIter - myVec.begin() would be a start.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Okay. Look at your algorithm and think about what it does.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Before:

compiler.exe ... -o aol_8.9.exe

After:

compiler.exe -O3 ... -o AOL_9.0_OPTIMIZED!!!111!.exe

At least that's my theory :-)

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Think carefully about how you store your data; and use floats when doubles aren't needed, shorts and chars when they suffice; and avoid memory leaks; and perhaps trade running time for memory. Process files incrementally instead of loading them all at once, whenever you can.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

You could put their site in an iframe and then position something transparent above the iframe. (And then your visitors wonder why they can't scroll.) Then you could expect a C&D in the mail.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I want to take control of my visitors' computers.

Write a Web browser that supports this somehow, and then ask your users to download this Web browser, and see if they like it.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

There is no practical purpose for this.

Therefore, this is a homework problem.

Therefore, show what you've tried, and if you demonstrate thought, you might get help.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

When Python is installed correctly, Python files should execute just like any other file -- it's just a matter of registering the file extension. It's the same situation as Java.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Erm,

if (num > max) {
    max2 = max;
    max = num;
}
else if (num > max2) {
    max2 = num;
}
Rashakil Fol 978 Super Senior Demiposter Team Colleague

You can't change the ordering of a map.

You want to copy the contents of your map to a datatype such as a vector, and then sort the vector by the value. You can do this using iterators.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Geeks play Subspace?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Make it more "powerful"? Exactly what do you mean?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

#1 has a solution but #2, without a set of base cases, is only solvable (I assume the "solution" that you want is for T to be defined in closed form) for one value of n.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

This article said, "Lots of people use HTML incorrectly, so therefore, use XHTML!" There's a gaping hole in that argument.

Coding HTML to the standards while closing closable tags is just as effective as using XHTML.

Not that there's anything wrong with XHTML. But this particular argument is rather flaky.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

...American lives are more valuable than non-American lives?

...Apologies don't mean that his opinion has changed.

Robertson's comments aren't as interesting (hence not as much media circus) because everybody knew he was a hypocrite anyway.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

For convenience, let f(n) = 6 * (2 ^ n) + n ^ 2.

What is this really saying? For all values of n that are reasonably large (greater than n0), show that f(n) is bounded by two multiples of g(n). Then c1 <= f(n) / g(n) <= c2. In other words, the ratio of the two functions doesn't grow towards infinity or contract towards zero -- it stays within a certain range. (This is slightly different than the definition I gave in the other thread. That's why I put the disclaimer on the bottom -- what you posted is the correct definition for theta notation.)

Here's where you just want to try different functions (for g(n)) and see how they work. (You'll get good at picking the right functions after a few practice problems.)

For example, the dominant (fastest-growing) term in (6 * 2 ^ n + n ^ 2) is 6 * 2 ^ n. Exponential terms grow faster than polynomial terms, that's why.

Now, suppose that g(n) = 2^n. Then we already know that 1 * g(n) <= f(n), that is, 2 ^ n <= 6 * (2 ^ n) + n ^ 2. This is true no matter what the value of n is. (Because 0 <= 5 * (2 ^ n) + n ^ 2, it follows that 2 ^ n <= 6 * (2 ^ n) + n ^ 2.)

Now we need to find a value c2 _and_ …

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I don't understand your question; maybe rephrase it. But maybe this will answer it:

O(expression) is the set of functions that grow slower than or at the same rate as expression. Omega(expression) is the set of functions that grow faster than or at the same rate as expression.

Theta(expression) consist of all the functions that lie in both O(expression) and Omega(expression).

Now here's one of my attempts to target directly at what your question seems to be saying:

Suppose you've calculated that an algorithm takes f(n) operations, where f(n) = 3 * n^2 + 2 * n + 4. Since this polynomial grows at the same rate as n^2, then you could say that the function f lies in the set Theta(n^2). (It also lies in the sets O(n^2) and Omega(n^2) for the same reason.)

Here are some false statements:

f lies in Theta(n).
f lies in Theta(n^3).

These are false because the function f grows faster than n and grows slower than n^3.

However, here is a true statement:

f lies in Theta(n^2 + 1).

This is true because the function f grows at the same pace as n^2 + 1. Here are some other true statements:

f lies in Theta(2 * n^2).
f lies in Theta(3 * n^2 + 2 * n + 4).
f lies in Theta((n^2) / 45).
f lies in Theta(n^2 + 1 - 1).
f lies in Theta(n^2 …

Rashakil Fol 978 Super Senior Demiposter Team Colleague

If you feel like reading this post slowly and carefully, it will describe what this notation _really_ means.

All functions have some kind of behavior as n grows towards infinity. For example, if f(n) = 1/n, then as n grows towards infinity, f(n) gets closer and closer to zero. Whereas if f(n) = n*n, then as n grows towards infinity, f(n) grows too.

Functions can grow at different speeds. If two functions are equal, then they obviously grow at the same speed. But wait, there's more! Two functions are deemed to grow at the same speed if they're separated by a constant multiple! For example, if f(n) = n*n and g(n) = 3*n*n, then f and g are deemed to grow at the same pace, because g(n) = 3*f(n), so they are only a constant multiple apart. That is, g(n) / f(n) = 3, as n grows arbitrarily large.

But consider the scenario where f(n) = n * n, and g(n) = n. Then what is the behavior of f(n) and g(n) as n grows arbitrarily large? Well, f(n) / g(n) = (n * n) / (n). Which simplifies to f(n) / g(n) = n. Which means that as n grows large, f(n) = n * g(n). What does this mean? f and g are in this case not separated by a constant multiple. The multiple between f and g grows larger and larger as time progresses, without stopping. We say that "f grows faster than g" …

Killer_Typo commented: incredible post, make me want to move farter and deeper into computers! +4
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Suppose you've got

for (i = 0; i < N + 1; ++i) {
    for (j = 0; i < N - 2; ++j) {
        some_constant_time_function(i,j);
    }
}

The total number of times some_constant_time_function() would be called is (N + 1)*(N - 2), is it not? Which expands to N^2 - N - 2.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Think about how the bit operations work.

Thanks.
I know how bit operations work, but I didn't want to let common sense get in the way of correctly divining the way of the C(++) standards.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

C restrictive? In what way?
Apart from Assembly C is just about the least restrictive language you can find, you can do almost everything you want (if you know how of course). And for the very few things you might not be able to you can always link to Assembly modules.

You can do anything you want on the machine, but that's not what I want.

But I'm talking about things like functions as first-class objects, closures (which C++ sort-of has, being object-oriented), and the like. C does not have those. Most languages are restrictive. (Practically all are.)

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Are you still a student? If not, how long have you been programming? Swapping integers (and other data types) is a common thing in sorting algorithms.

I am a student, and I've written most common sorting algorithms. Them being generic, I never end up swapping "integers", just some type named "T", via a third variable.

Swapping integers that are known to be integers (or unsigned integers, if signed integers actually do have problems) is just something I have not run into.

probably implemented like this

void swap(std::string& s1, std::string& s2)
{
   std::string temp = s1;
   s1 = s2;
   s2 = temp;
}

I know of no other way to do it with std::strings.

When implemented sanely, the std::string and maybe other datatypes' swap member function if they exist (used via x.swap(y)) simply swaps private pointers and length values if they exist. So swapping two million-character strings takes the same amount of time as swapping two zero-character strings.

As for xor producing overflow: I do not see how xor produces overflow problems. Which is what my question was about (it wasn't about sorting): Does xor have problems when a negative number is involved that causes x ^= y; y ^= x; x ^= y; to not swap the values of x and y when x and y are not the same variable? That is, is there a hypothetical case of internal binary number representation and xor operation where a C or C++-compliant compiler would produce machine code that does …

Rashakil Fol 978 Super Senior Demiposter Team Colleague

How is x ^= y; y ^= x; x ^= y; unsafe when x and y are equally sized integers? Is there a problem with using xor for signed integers? Well, I wouldn't really use it, because I've never swapped integers in my life.

As for swapping strings, there is a member function named 'swap' which tends to achieve the task in constant time.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

And as for #4:

y = x + (x << 1) + (x << 2);

also works.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

the answer to number 3 (assuming the number is an integer) is to use the modulous operator, %.

if(!(numbername%2))
   cout<<numbername<<" is a power of 2."<<endl;

Um, no. This only tells if the number is a multiple of 2. For power of 2, that'd be (!(x & (x - 1))).

As for #1:

First of all, "if" is not a loop. I don't know what got this idea into your head. But let's not use 'if' anyway.

#include <iostream>

void cout_nums_and_back(int low, int high) {
    (high < low)  ||  (
        std::cout << low << std::endl,
        cout_nums_and_back(low + 1, high),
        std::cout << low << std::endl
    );
    return;
}

int main() {
	cout_nums_and_back(1, 100);
	return 0;
}
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Does it matter of what interest the war is in? I'm guessing you would rather see millions of people being tortured and hung from soccer goal posts, but you are entitled to your beliefs.

Millions?
Oh, are you talking about Rwanda or something? Oh wait, we didn't do anything there.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Can anyone pl. mail turbo c++ setup as attachment to

I would recommend free software that exists and you can use for free, but you don't deserve it.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Maybe try writing down only the things you need to remember. It's not like you need to record a transcript of the lecture.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Maybe this is because you don't find C restrictive, whereas I do.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

You haven't used srand to seed the random number generator with say, the current time, so the random number generator outputs the same sequence of numbers every time you run the program.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I suppose you'll run into problems if the word ends up being "superconductors", or "Lackawannanians", or "indistinguishable", or "incomprehensible".

Rashakil Fol 978 Super Senior Demiposter Team Colleague

thats a good idea, but a group is already working on it. a few secs ago i came with the smart room thing. I have heard alot about it. i think it needs a blend of HCI & AI Knowledge. Do you have ne idea of it? actually i would love to comeup with something that uses face and voice recognition and other sensors within a room to personalize it for roomates when they enter. Is it worth implementing it ??

If you think that's a good idea, and if you're sure you can do it, then yes. I don't find it interesting, but I'm not you. I'd find recognizing people by the way they walk to be more interesting. Then again, I still think digital watches are a pretty neat idea.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Anyways, I'm just plain sick of hearing about it. It's all over the news. I just don't get why that women and other people let the war have so much affect on them. Why don't they let it go, support what's going on and shut up?

Absolutely, man! Ignorance is strength!

:rolleyes:

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Use 1 and c as your starting points; they'll always work, because the square root will always be between them. You can't really pick any fraction of c, like c/2, without testing its resulting sign first. And if you do that, well, you've already started the bisection process. So 1 and c work. Remember that c might be less than 1.

Those guesses aren't "optimal," because the optimal starting point would be the square root itself. So there's no need to look for optimal starting points -- just ones guaranteed to work all the time.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Make a chess playing program. You could make one in 3 days, but with a whole year you could try making it learn.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Good. The makers of software should get paid for their work if that's what they want. If I met you in person, I'd steal your clothes.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

You'll be lucky to get the $6.95 or whatever that you paid for it.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Record the time whenever the program closes. If the time when it opens is earlier than the previous closing time, it's been reset.

Or you could connect to one of your servers on the Internet and have it tell you what time it is, ignoring the user's clock completely.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Hi everione,

my next assinement is 2 do with classes. I dun no what they are tho and why u will use them? Can any1 explain them to me I would B greatfull.

You're taking a class and you want us to do work for you because you didn't feel like paying attention to your instructor?

Classes are a way of defining datatypes. GL on ur assininement.

HTHHAND. N!

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I need help with my big integer calculator program.

Okay.

The program should receive two large integers using vectors and calculate the sum, difference, product, and quotient o the two integers.

Okay.

The main file is:

Okay.

The header file is:

Okay.

What do you want?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

begin
Why would anybody want to use Pascal?
end;

You'll see it in Delphi, anyway, and I'm sure other people still use it. It's unpopular because it is a restrictive language, compared to others.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

For starters, you're trying to compare pointers, when you should be doing strcmp. plmove1 and "a1" are both just pointers to arrays of characters, to different arrays of characters, so they won't compare equally. Maybe (definitely) you should use the std::string datatype instead.

You still need to remove char from that line.