Infarction 503 Posting Virtuoso

It's just a case of lazy evaluation. if $ret is false, then $ret = $ret && foo() will never evaluate foo. The loop will execute 10 times, but the function call only as long as $ret is true.

MattEvans commented: Thanks for the tip. +2
Infarction 503 Posting Virtuoso

I prefer to use Sun's, since they're the ones who created the language. I don't know how others compare, though.

Infarction 503 Posting Virtuoso

lol.. I'm getting hustled here.. I like Daniweb, but I don't really like using my money.. I'm going to be paying off student loans for the rest of my life anyway..

I prefer to donate my time, it's just as good as gold! =)

A few bucks a month wont hurt you... unless you have serious credit issues... :P

Infarction 503 Posting Virtuoso

haha, I like how you just throw something in at the end thats on topic..

I wasn't begging for mod powers..? Is it only mods who are allowed in area 51? I just wanted to join the discussion..

Area 51 is for mods, admins, sponsors, etc.... The moderators then have their own forum.

Infarction 503 Posting Virtuoso

lol.. If you think any college student or soon-to-be college student has any extra money, then you must be on drugs =p

I scrounged some up, jbennet's saved up for it; you can too if you try hard enough.

Well, I can just see how area 51 is now.. All the mods and colleagues in there telling Dani to delete the games, give them superior power, etc.. lol. Perhaps there should be a neutral person, like me, in there making sure that every side is fairly represented =)

I assure you we're not all begging for mod powers etc... but don't you think that those who donate money or extensive time to the site should get a little something in return?

[edit:] on topic: I approve the new subforum (even though disapproving wouldn't change it now :P)

Infarction 503 Posting Virtuoso

Is it getting the day counts right though? Maybe if you just rearrange the values for the days it'll straighten out...

Infarction 503 Posting Virtuoso

Nope, you've got the loop. Remember, j is going from 1 to the current month. So if you pass j, it'll look up the days in the 1st, 2nd, 3rd, ... nth month. :icon_wink:

Infarction 503 Posting Virtuoso

I actually didn't test the leap year code. What's happening is you're adding the last year before it's over, skewing the result by that number of days. Ditto with the month. If you change the <= in getTotalNoOfDays to just a < it'll fix that problem. There's another problem in that you call getNoOfDaysInMonth with mo each time. That'll just call it with the same month over and over; you should be using j instead. It's like adding the days in April several times when you want to add January, February, and March instead.

Infarction 503 Posting Virtuoso

What exactly is the problem with all these 'games'? Even if we did move them to a separate forum, these games would obviously still be the most active.. Besides, I think the geek's lounge is a perfect place for geeky games.. There are very few discussions in the geek's lounge anyway..

damn, whats up with only html tags working now.. ie. for italics, breaks, and underlining..

As tgreer, WaltP, and I have been repeating lately, read what we're saying. There's nothing particularly wrong with the games, they're just poorly located. And, since you brought it up, they are hardly geeky. They physics game is the only one that could count as geeky IMHO, and it's almost off the first page.

Infarction 503 Posting Virtuoso

You add an extra year to the result, plus the number of days in the selected month. January 1800 comes out as 396, or 365+31.

Infarction 503 Posting Virtuoso

Okay, then why is everyone still arguing about it? If someone is doing something to try and fix the problem, then I think everyone should just stay calm for the moment and wade it out.

I agree. I think we've pretty much flushed out both sides by now, though I couldn't have said the same a few days ago.

Infarction 503 Posting Virtuoso

Maybe you should just read this post again. The part where is talks about 'PMing Dani.'

Dani is certainly aware of the problem. She's got a lot on her plate at the moment, but she's figuring out how she wants to handle the situation.

Infarction 503 Posting Virtuoso

There's nearly half a dozen people that have voiced strong opinions against the games being in the Geek Lounge. Don't keep saying that only one person is complaining. And the point we're trying to make is that if we don't go to the GL, we'll go elsewhere. And take our business with us. Daniweb as a whole will suffer, and we don't what that to happen. We understand your point, we aren't against the concept of the word games. We just don't want them clogging up the space that we'd rather maintain a more selective material. And AFAICT nobody has complained against the discussions.

Infarction 503 Posting Virtuoso

Also in agreement with tgreer. And while the gaming crowd seems to stress the "lounge" part of it, I prefer to emphasize the "geek" part of it. At this point, I'm spending more time going to other forums when I want some intellectual off-topic discussions. The games are in the way and annoying to work around; putting them in a separate sub-forum is a good way to keep them isolated for those who really want them.

Infarction 503 Posting Virtuoso

why not better work it out an even more simple way... get your string's length and create an array of characters as long as the string, which will substitute your string in the rest of the program. This way you can compare your guess individually with each element in the array...

i don't know... maybe it can make things a bit more simple...

That's about what WaltP suggested :icon_wink:

Infarction 503 Posting Virtuoso

I gave you some rep. And a comment.

:icon_rolleyes: :icon_rolleyes:

Infarction 503 Posting Virtuoso

It depends on the function you're calling. It could be defined as void foo(T* someArray, int arraySize, int otherValue) or as void foo(T* someArray, int otherValue, int arraySize) . The second one sucks, but you'll just have to check.

Infarction 503 Posting Virtuoso

Your code really needs to be indented for readability purposes.

Anyways, global identifiers are typically considered bad style. They still work, but if you can come up with a solution without globals, then you should do that. And since you return the user's choice anyways, why do you need to keep it in a global variable?

Infarction 503 Posting Virtuoso

Let's see if I finally get this correct for once:

int array[3];

array[0]
array[1]
array[2]
array[3]

Four elements in an a single dimention array.

No. Valid indices would be 0-2, for a total of 3.

int array[3][2];

array[0][0]
array[0][1]

array[1][0]
array[1][1]

array[2][0]
array[2][1]

Correct?

Yes

When you allocate an array, it basically tells the compiler "I want an array of N objects of type T". The compiler will lay those out in memory like so:

int arr[5];
|  0  |  1  |  2  |  3  |  4  |

Then when you index into the array, it takes the address of the first element of the array and adds the index to that address (it moves the index by the appropriate size of the data type, e.g. 1 byte for char, 4 bytes for a 32-bit int, etc..)

Infarction 503 Posting Virtuoso

int arrayOfArrays[2][3] will make an array of 2 integer arrays of length 3 each. A 2x3 if you will.

Infarction 503 Posting Virtuoso

If you're using C++, you should probably be using the std::string type rather than C-style strings (char*).

And your line strlen(getWord) = numLetters; is backwards. Try flipping it around. ;)

Infarction 503 Posting Virtuoso

How are you currently sorting them?

Infarction 503 Posting Virtuoso

vijayan's solution should be correct. There's a few things different between his and yours, though, which are important. First, his parameter takes a const object. This allows you to have a const Node on the right side of the expression. Second, he uses the pass-by-reference mechanism (the &) to avoid copying the node unnecessarily. Third, and the solution to your question, is the const at the end of the line which dictates that the function may be called for constant objects (which would be on the left-hand side).

Infarction 503 Posting Virtuoso

Not quite, it's

minimum + rand() / (RAND_MAX / (maximum - minimum) + 1 );

To ensure proper distribution.

:twisted:
(sorry, I couldn't help it :mrgreen:)

Actually, according to this very enlightening read, you're all wrong...

(sorry, I couldn't help it either) :mrgreen:

Infarction 503 Posting Virtuoso

That's true, but a work-around could be possible. For example, if memory isn't an issue, one could use a wrapper struct to maintain the original value and the square
root of the value, sort by square root, and then return the original values in sorted order. Sounds like a bit of extra work, but I think it could make the time complexity requirement.

Infarction 503 Posting Virtuoso

hm... just an idea... what if you tried applying any of the otherwise O(n) algorithms, but took the sqrt of the data as you sorted it. That would cut out the polynomial range, leavning you from 0..N, which is then polynomial time. You'd have to make an extra run over the loop at the end to square everything back to it's actual value.

Infarction 503 Posting Virtuoso

Well, in a normal case you'd be able to claim that radix sort, bucket sort, or counting sort (to name a couple) would run in O(n) time. But since they're all dependent on the range in some very small degree, seems like, the claim doesn't hold anymore.

Infarction 503 Posting Virtuoso

Since it does have the O(n log n) case, it wouldn't fit the requirements. And I've never seen an implementation of it outside of that paper... ;)

Infarction 503 Posting Virtuoso

> 1. Can I install a Ubuntu on a HDD with a Partition with 75 % 25%, and have linux on the 25% and a copy of Windows on the 75%?
Yes, but it's possible that you'll have to re-install Windows.

> 2. Is there any important software that I should get??
Depends on what you'll be doing. There's a few lists of applications on Windows and their corresponding apps on Linux that you can dig up somewhere.

>3. If i downloaded it in an .iso file, do I need to extract it and make a bootable disk? What i'm trying to say is if I can install Ubuntu like
> you would with like Windows 9* or XP??? Or Can i just boot from the .iso file?
Burn the .iso file as you got it, and it should be bootable.

Infarction 503 Posting Virtuoso

1. It does affect algorithm runtime in several cases, especially when dealing with non-comparison based sorts (since it's proven that comparision based sorts cannot be guaranteed to run in better than O(n log n) time, they don't make the cut for this problem). Look at some of the sorts already mentioned in this thread.

2. Linear time with respect to the length of the input.

Infarction 503 Posting Virtuoso

I don't think you even need Top3 (and you're using it uninitialized, which is bad). Top will be updated as you call pop, so you could probably just do:

while(Top)
  pop(Top);
Infarction 503 Posting Virtuoso

I tried running it and after a few small touchups (no logical changes though) it seems that you're off to a good start. Here's how it went:

$ ./a.out 
this is a line

enil a si siht

As you can see, it's working for single items and print_stack is fine :)

for push_string, you can just use a loop over the char*. Since it's really basic, I'll just show you:

void push_string(POINTER *Top,char *string)
{
  int i = 0;  // for indexing string
  while(string[i]) // while not end of string
  {
    push(Top, string[i]); // push item
    i++; // increment
  }
}

This could also be done pretty easily in a for loop.

Infarction 503 Posting Virtuoso

Just looking at the code for display, I'm surprised it doesn't crash.

void doubly::display()
{
  node *temp;
  temp=head;

  while(temp!=NULL)
  {
    cout<<temp->data<<"\t";
    temp=temp->next;
  }
  cout<<"\n";
  cout<<"\nnow printing in reverse order";

  while(temp->prev!=NULL)
  {
    cout<<temp->data<<"\t";
    temp=temp->prev;
  }
}

When you quit the first loop, temp will be NULL, as per the loop condition. Then when you try to start the second loop, you'll be accessing invalid memory trying to dereference NULL (and should crash). You'll can change the first loop to go until temp->next == NULL or you can keep a tail pointer in addition to the head one (where tail would record the last node in the list).

Side notes:
- <iostream.h> is deprecated. Use <iostream> and the std:: namespace in the future.
- <conio.h> is compiler specific and most people here would not be able to run your code.
- Why do you need <process.h>? Unless I missed something...
- Please use [code] and [/code] tags when you post code on the forums, as it preserves formatting (especially indentation) ;)

Infarction 503 Posting Virtuoso

Yeah, that's what I was thinking too. Even counting sort depends on the range of values, so it wouldn't fit either. I'm out of ideas, sorry :(

Infarction 503 Posting Virtuoso

You'll need a bignum library. I've seen mention of the Gnu Multiple Precision library before, so you might give that a shot.

Infarction 503 Posting Virtuoso

My first thought was a radix sort, but since that does depend on the value of the largest number, I'm don't think that it's strictly O(N) in this case.

Infarction 503 Posting Virtuoso

Not quite. The default access modifier makes things public only to the same package. Any class in another package will not be able to access the methods/members.

Infarction 503 Posting Virtuoso

Instead of giving a book answer, I figured I'd help you help yourself: did you try it? You can learn a lot just from experimenting and seeing if something works or not.

Infarction 503 Posting Virtuoso

I have so many songs in my library I don't even know what to listen to :rolleyes:

That's a problem? I repeatedly listen to about 1/2 my library so often I get sick of it... but I like it better than the other half, so I keep listening...

Infarction 503 Posting Virtuoso

You seem to be leaving out braces on your if statements. It was really easy to find with the code auto-indented. Here's a code excerpt:

switch (pkgType)
    {
      case 'A':
        if (hours > ONE )
          cout << "Package A " << PRICEA << hours
            << cost << endl;
        cost = PRICEA + ((hours - ONE) * EXTRA1);  // this will always get run
        break; // this will always get run
        // everything below this is unreachable code
        else if (hours <= ONE)
        {
          cout << "Package A " << PRICEA << hours
            << cost << endl;
          cost = PRICEA;
        }
        break;

That happens in all the case statements. I think you want something like this:

switch (pkgType)
    {
      case 'A':
        if (hours > ONE )
        {
          cout << "Package A " << PRICEA << hours
            << cost << endl;
          cost = PRICEA + ((hours - ONE) * EXTRA1);
        }
        else if (hours <= ONE)
        {
          cout << "Package A " << PRICEA << hours
            << cost << endl;
          cost = PRICEA;
        }
        break;

which could be further reduced to this:

switch (pkgType)
    {
      case 'A':
        cout << "Package A " << PRICEA << hours
             << cost << endl; // this line was the same in both the if and else
        if (hours > ONE )
        {
          cost = PRICEA + ((hours - ONE) * EXTRA1);
        }
        else if (hours <= ONE)
        {
          cost = PRICEA;
        }
        break;

btw, for future posts, please put your code between [code] …

Infarction 503 Posting Virtuoso

4302 songs, 24.76GB

Infarction 503 Posting Virtuoso

Actually, my brain wasn't really functioning either, now that I look at it. The no-brainer algorithm we all jumped on works so long as the coins are multiples of each other, or have a fairly high greatest denominator.

A more complicated algorithm would be about as follows:
1. Take the largest coin possible and subtract it. Now find the best way of creating the remainder, recursively.
2. Then take the next best option from the original amount, and recursively find it's best. If at any point, the best cannot be better than a solution already found, break. Compare this to the result for part 1 and keep the better solution.
3. Repeat 2 as feasible. In this instance, you'd only have to do it twice (once for toonies, once for jonnies), since a $2 is always better than 2x$1.

Infarction 503 Posting Virtuoso

To summarize the algorithm provided by Lazarus, you just add as many of the biggest coin you can. Then repeat for the next biggest until you have the amount.

Infarction 503 Posting Virtuoso

Ok, a list of things.

First, as Lazaro pointed out, main should be type int, not void. A return 0; is then implied, but most people add it for clarity's sake.

Second, on a matter of style: your use of nil is good, but you might consider using NULL like everyone else does. You can usually get it from <cstdlib> but I think it's in <cstddef> if you're really worried about being precise.

Third, another note of style. Instead of the *(ptr).member syntax, you can use ptr->member. Example:

firs->num = number; // (*first).num = number;
first->next = NULL; // (*first).next = nil; and following note 2

Fourth, more style. Your for loop condition is whacky. Since you wrote it, it's probably obvious to you that you're creating nodes 2-13. Most people reading this would probabaly do a double-take at first. To make 12 more nodes, most people would just do for(int i = 0; i < 12; i++) .

Fifth, yet more style. Putting a blank line between for or if constructs is also confusing. The common styles are same line or next line. And, if the enclosed block only has a single statement, you can get away without braces. With respect to that last, having a blank line looks really weird, to me at least.

Now we get into solving problems (I've just been writing these as I read the code :o)

Sixth: Now that we've hit the real code, time for …

Infarction 503 Posting Virtuoso

Lazaro, please do everyone else a favor and don't quote hugely long threads for a one line reply. Or, if you're quoting to that your reply has context, please trim the quoted part as much as possible. Thanks.

Infarction 503 Posting Virtuoso

> if (a(left) == b(left))
When did ( ) become the array subscript operator?

when [ left] got parsed out ;)

Infarction 503 Posting Virtuoso

You're getting close, but you're still missing some things. For instance, if left > size, you don't return anything, which should be a compiler error. You did try to compile the code first, right? Like joeprogrammer suggested, you could use an extra condition to check if you just compared the last elements. Or, you could return true if left >= size, which would be just in an else block (fixes the above error as well, but someone could just call the function with the wrong left or size to get it to return true).

Other than that, it should be if(left < size) because of 0-based counting (the legal range of indices are 0 to size-1).

Infarction 503 Posting Virtuoso

Try running through your code on paper, as though you were the computer. You'll see that you're not using the left variable for anything, except the +1 before recursing. And you'll recurse infinitely unless a and b are different. Which they almost always will be, unless you're comparing an array to itself. You need to index the arrays (using left) and check for bounding errors to make sure you don't go over the length of the arrays. ;)

Infarction 503 Posting Virtuoso

and is there a logical problem with your code...?

By the way, main should return a type int ;)

Infarction 503 Posting Virtuoso

Unfortunately, it won't always be accurate unless you go to great pains. This is due to there being multiple rules (and exceptions to those rules) for the English language.