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

and should i be able to run both vc6 and Dev C++ 4 on the same computer and same hard drive partition.

Yes, they are just two different applications that do the same thing. ;)

Infarction 503 Posting Virtuoso

Ok, I'll put this bluntly: I'm not going to post any code here. You need to figure it out on your own. I gave you a list of things you need to do as well as several suggestions for how to continue after that. I will not do your work for you. I don't have time to do your work. You can't afford to pay me to do your work. You'll need to do your work. Did you even read my second post?

Infarction 503 Posting Virtuoso

Number one recommendation: run your code through a compiler. There's a few really simple bugs in it. Like missing semicolons, inconsistent capitalization, and using = = instead of == . Anyways, moving on...

public MobilePhone() throws IOException
  {
    BufferedReader r = new BufferedReader(InputStreamReader(System.in));
    System.out.println(" Phone details")
      System.out.print(" input your own phone number:");
    int ownNumber = Integer.parseInt(r.readLine());
    System.out.print("Input the number to call:");
    int calledNumber = Integer.parseInt(r.readLine());
    Boolean status = free;
  }

You're missing a semicolon after the first System.out.println, and you're trying to declare status locally (and Boolean shouldn't be capitalized, but in this case it should just be removed). If you're using Java 1.5 or later, check out the java.util.Scanner class. It makes input from the console a lot easier, where you can do things like this:

Scanner consoleInput = new Scanner(System.in);
int anInt = consoleInput.nextInt();
String aWord = consoleInput.next();
String aLine = consoleInput.nextLine();

setData is exactly the same as the empty constructor. You could just have the constructor call setData to avoid duplicated code.

Why do you set the number to call in setData when you're just going to prompt for it in dial? Choose one (probably dial). And then dial needs to try connecting and set the status accordingly. That's logic you'll have to figure out.

In call, when you have if(status == busy) , are you checking if the current phone or the dialed one is busy? Depending on your requirements, there might be a need for both. If the current phone is …

Infarction 503 Posting Virtuoso

pass the pointer and the length of the array.

Infarction 503 Posting Virtuoso

Hmm, well if the instructors used the latest version it wouldn't permit (or at least give lots of warnings, I haven't actually installed 2005 edition yet) the use of these old headers.

VS2005 does give a warning, IIRC. ;)

Meh, that statement was completely meaningless since VS 2005 won't even compile modern headers without giving warnings. Maybe I'll just go and hide...

Won't compile modern headers? How so? (not that I've used it much for anything C++ related...)

Infarction 503 Posting Virtuoso

Please post whatever changes you've made to the code. You keep saying it's not working, and we keep saying it should work.

in main it should say
if ( small || large<0)
cout << "NOTHING TO PROCESS" <<endl;

The logic on that line is wrong, period. If small is 500 (valid input), it'll evaluate to true, and print the message.

Infarction 503 Posting Virtuoso

You could initialize both smallest and largest to -1 back in main before calling determine. This will eliminate the initialization problem, and you can use the method I suggested above for setting smallest on the first inputted value. Then in main, your if statement for "nothing to process" could look like this:

if(smallest < 0) //  nothing or negative value inputted
  cout << "nothing to process" << endl;
Infarction 503 Posting Virtuoso

If long double doesn't do it, I'm not sure. If you desperately need the precision, you could also use a 3rd party high (or arbitrary) precision library.

Oh, and unless you absolutely need VC6.0, I'd recommend you upgrade to something from this millenium. There is a free version of VC available from Microsoft even ;)

[edit:] quite the race going on here :p

Infarction 503 Posting Virtuoso

Before I comment on this function, it should be noted that smallest and largest are not initialized when passed to determine

void determine ( int &smallest, int &largest)
{
  int A;
  A=smallest;
  A=largest; 
  while(A>=0)  
  {

Why do you set A right here? A should be the number inputted by the user. That said, you might consider using a do-while loop instead of while, so that you can enter the loop and get input before you check whether to repeat the loop.

cout << "Please a number (Negative value to end): ";
    cin >> A;
    if(A<0)
      return;
    if (A<smallest)smallest=A;
    if (A>largest)largest=A; 
  }
}

Small things here. You don't validate the input, so if the user puts something like "asdf" your program will likely go up in flames. For smallest, you have to be careful. If you initialize it to 0 at the beginning, it'll never have something less. You'll want to set it to the first value the user enters. I'd set it to -1 and have another if statement for that case (and before anyone blows up about inefficient design, the speed bottleneck is the user input, so an extra if statement won't be noticeable).

Infarction 503 Posting Virtuoso

Now I'm getting confused. What are we talking about, compilers or IDEs?

Good point. I made the assumption that the OP wasn't sure of the difference and considered them the same.

Infarction 503 Posting Virtuoso

Try just using <iomanip>. I'm guessing that you have VC6.0 or something at school, which uses old (deprecated) headers. The standard C++ headers don't have the .h extension. Unfortunately, lots of classes still use old compilers (like VC6 which even predates the C++ standard) and make it very annoying to move back and forth from class and home. If this is the case, you might also ask your instructor to consider upgrading, but do tread lightly there.

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

WELL..I SEARCHED GOOGLE..I FIND OREGON TRAIL BUT NOT ITS JAVA CODE!! I WISH ANYONE HAS DONE IT IN JAVA

I'm just making an assumption here, but I'd guess that you've not been on many forums. Don't take this wrong, I'm not trying to insult you, but just to help you learn a bit: capital letters should be avoided. It's usually interpreted as the equivalent of yelling. We can read it just as well if it's upper or lowercase, so in the future please stick to lowercase.

That said, it's highly unlikely that anyone has written it in Java before.

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

I'm thinking google would be the place to look. Don't know if you'll have much luck, Oregon Trail isn't one of those games that people tend to throw together for fun. Good luck though ;)

Infarction 503 Posting Virtuoso

I certainly hope you don't expect us to write the code for you. Not only is it dishonest (we call it "cheating" around here), but there's no point. It's highly doubtful that you'll learn much if anything from it (don't argue, we've heard it before). Maybe you should have paid better attention in class, asked your professor for help, and gotten a book sooner.

On the other hand, if you were to post some incorrect or slightly incomplete code with a description of what's wrong, I'm sure a lot of members would be much more willing to help you get over a couple problems... ;)

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

Wow, that's an impressive story. Glad to see that the law isn't above the law in that case ;)

Infarction 503 Posting Virtuoso

It depends on what I'm doing as to what I'll use. Also depends on the computer I'm on. For helping people on the forums here, I tend to just use gcc from the command line (and a console text editor). Really lightweight for small (e.g. single file) projects. If I was going to do a relatively large project, I'd probably use Visual C++, just 'cause I'm used to its layout and I'm comfortable with it. If you're looking for one, try a few out (VC++, DevCpp, Code::Blocks) and see which you're most comfortable with.

Salem commented: *nods* - Salem +6
Infarction 503 Posting Virtuoso

If you want to repair computers, an A+ would probably be suitable. If you want to repair Windows installations, probably an MCSE cert is the way to go. For Linux stuff, you could consider Red Hat's certifications, though the material won't apply universally. Other distros might also have something. For networking, look into Cisco's line of certifications (CCNA, CCNP, and CCIE if you're crazy good) (while these not vendor neutral, they are still highly valued). I don't know what's out there for webmaster certs.

Infarction 503 Posting Virtuoso

without removing duplicates, you could just replace any spaces with a newline:

sed "s/ /\n/g" originalFile > outputFile

This won't remove punctuation, but you could write another one to do that.

*code not tested, but pretty sure it'll do the trick

Infarction 503 Posting Virtuoso

There's a lot of comics these days that are really boring. When I look through the Sudnay paper I pick out only a couple... and I don't even remember all of them (but the list includes The Duplex, Foxtrot, and Sherman's Lagoon).

I do read a few webcomics too... Questionable Content, xkcd, Ctrl-Alt-Delete, PHD comics, and Dr. McNinja. Sometimes they get a little bland too, but they're more enjoyable than most of the comics in the paper.

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

I'd say you'd be using the array as a hash table. Sorry for digging up a 4-day old thread ;)

Infarction 503 Posting Virtuoso

This thread has a duplicate in the C++ forum. I suggest this one be closed, if a mod would be so inclined. Please don't double-post in the future. ;)

Infarction 503 Posting Virtuoso

I am not completely agree with you in the first algorithm
...
Since, we have m=m/2 , and the outer loop will continue till n.
But when m=1 then the inner loop doesnt work

but then we come to m=m/2 again, and 1/2 == 0, so m == 0, and m is even. So from there the inner loop will always run.

And for the Second Algorithm, I am sorry I made a mistake in it, so it should be:
-------------------------------------------

while(m>1) do
       if m is even then
           for j=1 to log n
           count ++
           end for
           m=m/2
      end if
end while

-------------------------------------------

if m is odd and greater than 1, it'll have an infinite loop still. Maybe you meant this:

while(m>1) do
       if m is even then
           for j=1 to log n
           count ++
           end for
      end if
      m=m/2
 end while

in which case, the outer loop will run log(m) times and the inner one will run (worst case) each of those times. At log(n) for the inner loop, we get O( log(m) * log(n) )

Infarction 503 Posting Virtuoso

dmesg will show you the last 500 or so lines from the kernel log. You can read through /var/log/messages (on any system I've been on at least) for a more verbose list (this is the file that dmesg actually parses for you). In either case, less is very handy for reading through the output.

Infarction 503 Posting Virtuoso
m = n
for i=1 to n
    if m is even then
        for j=1 to log n
          count++
        end for
   end if
m=m/2
end for

For this one, you'll run the outer loop n times (1 to n). For a large integer n, you'll end up running the inner loop most of the time, and it iterates log n times. So, for each iteration of the outer loop, you do log n work; since there's n iterations of the outer loop, you multiply them and get O(n log n).

while(m>1) do
    if m is even then
       for j=1 to log n
         count ++
       end for
    end if
end while

For m>1, this doesn't end. For m<=1, it runs in constant time, since it never executes the loop.

You should read this page for a description of time complexity.

joshuatree commented: hit the nail on the head +2
Infarction 503 Posting Virtuoso

My guess would be that t->b_num wasn't initialized properly. Mind you, this is very much a guess. I can't run your code so I can't tell for sure, and you didn't post what the exception was, but I'm assuming it's due to an improperly initialized pointer (in this case the members of t were not set properly).

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

I just had 3 cups of tea in the last hour, and that was just to relax. Wasn't caffeinated since I don't want to be up all night, but that's about how fast I go through it when I'm drinking a lot of tea. Probably not as much as other people, but enough to keep me going ;)

Infarction 503 Posting Virtuoso

Not MEPIS's fault that you didn't burn the iso right. Don't blame MEPIS for your mistakes.

I know how to burn an ISO. The installer froze each time I tried loading it.

Infarction 503 Posting Virtuoso

Tea.
Other tea.
Some more tea.
A couple forms of pop
And occasionally some coffee.

Chocolate is also good, but not for the caffeine...

Infarction 503 Posting Virtuoso

My last words on the topic:

You run the same kernel (actually, from what I can tell, you're running the one I installed a year ago; I've updated since). You use the same packages (and likely the same package manager as many other distros as well). How does that make your distro better than the ones I've already got configured the way I like?

Infarction 503 Posting Virtuoso

a hole

Infarction 503 Posting Virtuoso

Linux needs to be unified... Someone needs to set the standard, and stick with it. That is why MS windows is so great. They have unity.

While it might be handy for some aspects to be standardized, I think you'll find that most Linux users would not like it to be unified. The locked down "unity" of Windows is actually kind of annoying to me anymore...

Infarction 503 Posting Virtuoso

Most distros will offer pretty much the same packages. Sometimes one distro will have a package another doesn't but you can always install it w/o the package manager as well. The difference between distros is basically the packaga manager, the branding, and the community.

We get a lot of x-ubuntu, x-gentoo and x-fedora users coming to MEPIS and not the other way around so that says something. ;)

How do you know it's not the other way around? ;)

Infarction 503 Posting Virtuoso

Except multiple returns from a single function is frowned upon.

That's more a matter of style for ease of maintenance, AFAICT. IMHO, this function is more clear this way, though if you want a single return, it could be done as

int max(int a, int b) {
  return (a > b ? a : b);
}

but I didn't want to post that one for clarity's sake.

Infarction 503 Posting Virtuoso

this line

while(inWordFile>>(fgets(line, 100, stdin)))

is roughly saying:

while( read in a word from inWordFile and store it in 
                (read in 100 chars from stdin and save it in the variable line))

That won't work, since you need to save the word in a variable. Hence this:

while( inWordFile >> word)
//while ( read in a word and save it in a variable called word)

For this to work, though, you'll need to use the std::string type (#include <string>). The string type will handle arbitrary size strings, so you don't have to worry about buffer overflows. And the whole business of copying pointers won't be an issue either.

Now that I'm thinking about it, it doesn't look like you were copying data before either. So all of your BSTNodes would have ended up with the same string, since all of their pointers would point to the same memory. Here's how that would happen:
- you'd put the new word in the character array called word.
- you'd add that to the tree, and the new node would point at the char array
- you'd read a new word into the char array. This would change the word for the first one as well, since they point to the same memory.
- you'd add the new word to the tree. Since it would have the same value as the old one, you'd just increment the counter.
- repeat as necessary
At …

Infarction 503 Posting Virtuoso

This line looks weird to me:

while(inWordFile>>(fgets(line, 100, stdin))){//read the file a line

If you were using the std::string class instead of c-strings (char*), you could just do something along these lines:

string word;
while(inWordFile >> word) {
  if(!notWord(word)) // though I'd change it to if(isWord(word))
    root = insert(root, word);
}

There'd be some smaller changes in your other code, but I think it'd do about what you're aiming for...

Infarction 503 Posting Virtuoso

Just so's you know -
Gentoo: emerge ntfs3g
Ubuntu: apt-get install ntfs-3g
Fedora: yum install ntfs-3g
and that's just the distros I run...

Mepis ain't that special ;)

Infarction 503 Posting Virtuoso

you should just output the maximum of the two:

cout << "the max is " << max(firstnum, secondnum)) << endl;

that said, your max function is wrong. It finds the max but should return the result. Here's a cleaner version:

int max(int a, int b)
{
  if(a > b)
    return a;
  else
    return b;
}
Infarction 503 Posting Virtuoso

4302 songs, 24.76GB

Infarction 503 Posting Virtuoso

what about something like this:

#!/bin/bash

for file in `find ./ -iname $1`
do
  rm $file
done

Not tested, but I think it'll work. You'll have to give different flags to rm if you want it to remove directories as well...

Infarction 503 Posting Virtuoso

Don't knock MEPIS till you have tried it. A remark like yours seems biased. I have used every version of MEPIS since 3.3, released in 2004. I can boot to 3.3.1-1, 3.4.3, 6.0, 6.5 beta 7(two installs) 6.5 rc1 (also two installs) knoppix 5.1.1 and the latest debian etch last was out last week. MEPIS is the best for new users or for old pros. It just works. And now with ntfs-3g we can read and write to ntfs so there. MEPIS is the best. :D

I couldn't get the MEPIS 6 installer to run when I tried it and I didn't feel like burning another image, but it cant be that different from the other popular distros. and ntfs-3g is available for anyone, so there.

And next time I knock it, I'll use [sarcasm] tags...

Infarction 503 Posting Virtuoso

that's an old one... Nothing.

btw, you guys can just take my turn. Coming up with riddles seems harder than solving them... what am I? lazy :p

Infarction 503 Posting Virtuoso

Most common distros will run on 256MB though they may be slow. Ubuntu is probably one of your better bets for a quick setup and easy to use system. You might want to look at Kubuntu as well, which is simply Ubuntu with KDE as the desktop manager (this way the default appearance is "more like windows").

I've not used DSL, but the footprint for it isn't a feature in this case; you should be fine with a full distro, just minus the extra eye candy. I don't know how difficult it is to setup, but I'm willing to bet it takes a lot more effort than Ubuntu....