Narue 5,707 Bad Cop Team Colleague

>Can someone explain me what does this mean?
>"40[^\"], %*c"

Assuming it's actually "%40[^\"], %*c", it means read a string of up to 40 characters or until a double quote is found (%40[^\"]), then match a comma, any amount of whitespace, and ignore the next non-whitespace character (%*c).

The %[ specifier is a scanset. It's used to search for a collection of characters and either match based on the scanset or match based on its exclusion (a ^ as the first character means that the scanset is an exclusion scanset).

The * modifier is called assignment suppression. It means that whatever is read will not be assigned to a variable in the argument list. The conversion is simply thrown away.

The format string you posted is actually broken in that it won't get past the scanset because the scanset stops on a double quote character without extracting it. The correct format string would be:

"%40[^\"]\", %*c"

Or to be more strictly correct if there are likely to be more characters in the scanset:

"%40[^\"]%*1[\"], %*c"

This is ignoring the case where the field width ends the scanset specifier rather than one of the scanset character matches.

jephthah commented: well, damn. how bout them apples? +5
Narue 5,707 Bad Cop Team Colleague

You'd think in time these kids would grow up, I dunno maybe start dating, and realise there's more to life than looking leet on an internet forum?

This is a hoot. iamthwee, the personification of childish behavior, is suggesting that someone else needs to grow up. :D

Narue 5,707 Bad Cop Team Colleague

>Anyway, you are perma-banned from daniweb.
That's worked soooo well, as we can plainly see. I think it's high time for Dani to complain to Josh's ISP and see about getting his account dropped. If he can't connect to the web, he can't circumvent his forum ban, can he?

Narue 5,707 Bad Cop Team Colleague

>First - unlike the most of you, I've read Microsoft's financial reports, and understand accounting.
I find that statement somewhat insulting. "Unlike most of you, I know what I'm talking about...". Presumably you think "most" of us are oblivious pimple-faced kids in our parent's basement living off of ramen noodles and soda pop. At least, that's what your tone suggests.

>I know how much money Microsoft has on hand, and how unlikely this scenario is.
It doesn't exactly take a huge stretch of the imagination to realize how unlikely this scenario is. Just how stupid do you think we are?

>I'm not trying to insult you.
If you weren't trying then you're a natural!

>I'm asking what you would do in a theoretical situation.
Windows is pervasive enough that I doubt it would just go away if Microsoft went bankrupt. Someone would get a hold of it and keep it going ("someone" being Apple or Sun, most likely). I would keep doing what I'm doing now: constantly evaluate my needs versus the available tools and use them accordingly.

>Third - I'm going to be posting the same question in several places.
I can see it now. You use two or three of us as sound bites, out of context so as to make anything we say support your conclusion, and then claim "most of" the industry feels the same way.

>I am assuming that a response to this post means …

lllllIllIlllI commented: ka ching! :P +0
Narue 5,707 Bad Cop Team Colleague

Mixing C++/CLI and standard C++ can be troublesome. Try sticking to one or the other unless you have good reason not to:

label2->Text = Convert::ToString ( a );
Narue 5,707 Bad Cop Team Colleague

You're working with uninitialized pointers. Pass the matrices as references:

void generate(int**&, int, int);
void fill(int**&, int, int);
int** compute(int**& ,int**&, int, int, int, int);
void dellocate(int**& val, int x, int y);
void display(int**& val, int x, int y);

Match that in the definitions, and that's the only change you need to make.

Narue 5,707 Bad Cop Team Colleague

>Hmm, That's very odd!
Not especially, though it can be surprising. This is the underlying problem:

#include <iostream>

#define UNICODE
#include <windows.h>

int main()
{
  TCHAR *s = L"test";

  std::cout<< s <<'\n';
}

My crystal ball says the UNICODE macro is defined, which causes CString to resolve to an actual type of CStringW. The implicit conversion ends up actually being CStringW to wchar_t*, which cout (the narrow stream object) isn't built to handle. Two simple options are to undefine UNICODE (if you don't need Unicode in the project), or use wcout instead of cout.

JasonHippy commented: Thanks Narue, I hadn't come accross that before! +1
Narue 5,707 Bad Cop Team Colleague

>Now the question is how the Assember was implemented, i mean which language?
Any compiler can be written in a suitable existing language. The first assembler was probably hand compiled as machine code. Then the second assembler could be written in assembly language and compiled using the first assembler.

>how they are written i mean using which language?
Any language suitable for a compiler or interpreter.

>i read, c compiler was wirtten in C itself .
>then how it was compiled.

With an existing compiler. The first C compiler was probably written in assembly, or some other language that predates C (like B). Then the second compiler could be written in C and compiled using the first compiler. Notice a pattern?

Iam3R commented: i think you the real code God S +1
Narue 5,707 Bad Cop Team Colleague

>i cant drop it now ! or i'll have another semester ! cause of these 3 hours ! so no i wont drop it .
Then ! you're ! screwed ! aren't ! you? Daniweb is not a homework service. If you want to learn C++ to get the job done (unlikely in the amount of time you probably have), we can answer specific questions. Otherwise, if you want someone to do it for you, you're encouraged to piss off.

Narue 5,707 Bad Cop Team Colleague

>am an engineering student and took the AI course by mistake !
So drop the course. You can do that, you know.

Narue 5,707 Bad Cop Team Colleague

No code, no help. Read our rules.

Narue 5,707 Bad Cop Team Colleague

>but many books have this specifier.
I hate to break it to you, but many books are written by people who know little more about C than you do. The lesson about %lf is that printf is not a mirror image of scanf in terms of format specifiers.

>where can i find the information related to the format specifiers.
A good book will cover them accurately. A good reference will cover them. And of course, you can refer to the standard itself, though it's a bit harder to glean useful information until you learn how to decipher the legalese.

Iam3R commented: thanks ,its very helpfull +1
Narue 5,707 Bad Cop Team Colleague

>I’m using dev c++ with the default gcc/g++ compiler,
>and this exact code works fine for me

There's nothing to stop a compiler from including standard headers in other standard headers. In your case, <iostream> includes <string> somewhere along the line. However, it's extremely poor practice to rely on this kind of behavior.

>what do you mean by "there are still issues"?
Cleaning up the output, checking user input for success/failure...that kind of thing. It's not a huge deal at this point in time, so I didn't mention those things.

Narue 5,707 Bad Cop Team Colleague

>I did not get an error using vc++ 2008 express, compiled for both C and C++ and was ok.
Visual Studio gives a warning when compiled as C because it supports this as an extension. Assuming the OP is compiling as C89, the error when removing static is legit because C89 requires aggregate initializers to be constant expressions. C99 and C++ don't have that restriction, IIRC.

Narue 5,707 Bad Cop Team Colleague

Two replies (one from a mod), and both are horrid. You both completely missed the fact that the <string> header wasn't included, which means any use of the std::string try (qualified or no) will fail miserably.

*sigh*

Here is the corrected[1] code. I added the <string> header and qualified the types because the OP was using explicit qualification for cout and cin:

#include <iostream>
#include <string>

int main()
{
  std::string firstName;
  std::string lastName;
  int salary;

  std::cout << "Enter First Name, Last Name, Salary";
  std::cin >> firstName >> lastName >> salary;

  std::cout << "\nFirst Name is " << firstName;
  std::cout << "\nLast Name is " << lastName;
  std::cout << "\nSalary is " << salary;

  return 0;
}

[1] There are still issues, but the immediate problem has been fixed.

kvprajapati commented: Good suggestion! +6
Narue 5,707 Bad Cop Team Colleague

Q: Do you know how to do it on paper?
(a) No: Go figure that out before trying to write code.
(b) Yes: Show us your code, and be more freaking specific about what problem you're having.

Since you didn't post any code, I'll assume your answer to the question is (a). All too often we get people who have no idea how to solve the problem and rush off to write code. It's like building a bridge without a blueprint. Stupid.

Narue 5,707 Bad Cop Team Colleague

>it won't work the way i want it
So fix it. We're not the psychic friends network, here to solve all of you problems with a crystal ball and smile. You wrote the damn program (and it's very short!), so you should be able to figure out why it's not doing what you want.

I'll direct you here because you really need it.

Narue 5,707 Bad Cop Team Colleague

>i read that the precision of float is 6 digits and double is 10.
No, the precision of float is FLT_DIG and double is DBL_DIG, where both of those macros are defined in <float.h>.

>but it is showing only 6 for both.
Yes, that's the correct behavior. If you print a floating-point value using printf and no precision specification, the precision is assumed to be 6. You can find this as a stated requirement in the standard for the %f specifier.

>float f = 34.34567832;
You'll most likely get a warning about precision loss here. float constants are suffixed with f or cast to float:

float f = 34.34567832f;

>printf("%lf\n",d);
There's no such thing as thing as %lf. You've invoked undefined behavior by using a length modifier that doesn't apply to the type specifier. %f is for double and %Lf is for long double. Because printf is a variable argument function, all of the variable arguments follow the regular type promotions, which means that float gets promoted to double. Therefore there's no specifier for float in printf.

Try this instead:

#include <stdio.h>
#include <float.h>

int main ( void )
{
  printf ( "Float precision:  %d\n", FLT_DIG );
  printf ( "double precision: %d\n", DBL_DIG );

  printf ( "float value:  %.*f\n", FLT_DIG, 34.34567832f );
  printf ( "double value: %.*f\n", DBL_DIG, 34.3456783221 );

  return 0;
}
Narue 5,707 Bad Cop Team Colleague

>Is there any suggestion for improvement
Yes, I can recommend improvements:

>scanf("%d",&n);
Always check your input functions for success. Especially with user input, and more especially with functions that are being used inappropriately (like scanf for user input), you need to take care that it read what you wanted. You can also use that opportunity to make the input more friendly and robust:

#include <stdio.h>
#include <stdlib.h>

int main ( void )
{
  int n;

  {
    int tries = 3;
    int extra_ch;

    printf ( "Number of integers? " );
    fflush ( stdout );

    while ( scanf ( "%d", &n ) != 1 ) {
      /* Give up after too many tries */
      if ( --tries == 0 )
        break;

      /* Notify user of the error */
      printf ( "Invalid input. Please try again: " );
      fflush ( stdout );

      /* Tidy up for the next attempt */
      clearerr ( stdin );

      do
        extra_ch = getchar();
      while ( extra_ch != '\n' && extra_ch != EOF );
    }

    if ( tries == 0 ) {
      printf ( "Too many failures. Bailing...\n" );
      return EXIT_FAILURE;
    }
  }

  printf ( "You entered %d\n", n );

  return EXIT_SUCCESS;
}

>p=malloc(n*sizeof(int));
First and foremost, malloc can return a null pointer. You need to check for that. Second, there's a way to use malloc without relying on the type of p:

p = malloc ( n * sizeof *p );

if ( p == NULL )
  panic();

The nice thing about …

Narue 5,707 Bad Cop Team Colleague

>How could I take something like that and make it recursive?
Loops are simulated using recursion, so your first step should be to take the loop and turn it into recursive calls without losing the changes made to local data.

The condition of the loop represents a base case, so you can do something like this:

Bignum modpow_r(Bignum base, Bignum exponent, Bignum modulus) {
  if (exponent > 0) {
    // Recurse
  }

  return /* something */;
}

You know how the algorithm works, presumably, so you can fill out that part a little bit before hitting a stumbling block. What do you do with result so that it persists between recursive calls?

There are generally two options for a persisted object. If you can build the value of the object when returning back up the recursive chain, you don't need a variable for it. This is more of an ideal recursive solution:

Bignum modpow_r(Bignum base, Bignum exponent, Bignum modulus) {
  if (exponent <= 0)
    return 1;

  Bignum next_base = (base * base) % modulus;
  Bignum next_exp = exponent >> 1;
  Bignum result = modpow_r(next_base, next_exp, modulus);

  if ((exponent & 1) == 1)
    result = (result * base) % modulus;

  return result;
}

Alternatively, you can use function parameters as the persisted objects and simply pass them in. This is typically a closer match to the iterative solution:

Bignum modpow_r(Bignum base, Bignum exponent, Bignum modulus, Bignum result = 1) {
  if (exponent > 0) { …
Narue 5,707 Bad Cop Team Colleague

>Might the sir be needing anything else?
For future reference, please be aware that email addresses in posts are against the rules and extremely likely to be removed by the moderators. If you quote the email address, that doubles the work required to clean up the mess because the mod has to edit both the original post and the quote in your post. So please snip judiciously if you must reply to posts that break the rules.

Narue 5,707 Bad Cop Team Colleague

inline: Similar to C++'s inline keyword. It gives you the option of telling the compiler that you want inline expansion rather than real function object code. Inline functions are a safer and easier to use alternative to function macros:

static inline swap ( int *a, int *b )
{
  int save = *a;
  *a = *b;
  *b = save;
}

I'd recommend avoiding this feature. Not only are the rules somewhat tricky, the compiler isn't required to honor a hint for inlining. Further, if the compiler does honor the hint, it could be counter-productive and actually hurt performance instead of help it by increasing the memory footprint and causing thrashing.

_Bool: C99's boolean type. Using _Bool directly is only recommended if you're maintaining legacy code that already defines macros for bool, true, or false. Otherwise, those macros are standardized in the <stdbool.h> header. Include that header and you can use bool just like you would in C++.

#include <stdio.h>
#include <stdbool.h>

int main ( void )
{
  bool b = true;

  if ( b )
    printf ( "Yes\n" );
  else
    printf ( "No\n" );

  return 0;
}

restrict: The restrict keyword is an optimization hint. It says that a pointer is not aliased in the current scope, which means the underlying object is not accessed by another pointer. This hint gives the compiler extra leeway in making assumptions about the pointer and can result in better object code. I'd recommend avoiding this feature too. A lot of …

Iam3R commented: thanks +1
Ancient Dragon commented: Nicely written info :) +25
Narue 5,707 Bad Cop Team Colleague

In my free time I kick puppies and shoot kids with a paintball gun.

jbennet commented: awesome +0
Dave Sinkula commented: I knew it! :p +0
Narue 5,707 Bad Cop Team Colleague

>And here int edadMedia(struct persona * nombres) { }
>i wanted to create a pointer to an array of structs

That close to what you said, and personally I think it's what you really meant. When you pass an array to a function, it becomes a pointer to the first element of the array. Therefore, an array and a pointer to the first element of an array are equivalent as function parameters.

In summary: nombres is an array. You pass nombres to edadMedia which is a function that expects an array. Therefore, all you need to do is use nombres inside edadMedia as if it were an array and you'll be solid.

>That's what i'm using (-std=C99)
And that possibility is why I didn't say you were wrong. :)

>shouldn't i use C99 even being more modern than C89?
C99 still isn't widely implemented and despite being the current standard, is far less portable than C89. That's why I generally recommend using an intersection of C89 and C99. That way your code is portable under both standards.

>Isn't EOF the standard way to say that's the end of the file?
1) EOF is not a character in the file.
2) fgets never gives you the EOF macro, in any form.

You're thinking of fgetc, which returns EOF when it detects either an error or end-of-file:

int ch;

while ( ( ch = fgetc ( in ) ) …
Narue 5,707 Bad Cop Team Colleague

If you want to be able to roll back changes, store the contents of the vector in a backup vector before making the changes. Alternatively, you could reverse your algorithm to obtain the original values, but the backup vector is easier and faster (at the cost of extra memory usage).

Narue 5,707 Bad Cop Team Colleague

>You can also do this: <snip conio.h crap>
You can do that...but don't teach it to others. Using conio.h is like bumping uglies with a fat chick. A lot of guys might do it, but they don't talk about it. Such is the way with bad programming practices.

jbennet commented: n/a +22
Narue 5,707 Bad Cop Team Colleague

>goto /*line*/ 18;
goto is restricted to a single function, you can't jump between functions with it.

>conio.h is an older c header file and is deprecated in C++...
Please don't use deprecated to mean anything except "standard, but not recommended because it might not be standard in the next revision". conio.h was never standard, either in C or C++.

>There is an equivalent C++ header to access the same functionality as conio.h
No, conio.h provides functionality that isn't portable, and is thus unavailable in the standard library. However, you can get close for things like getch. cin.get can "pause" the program just as well[1], with the added restriction of the user having to press the enter key:

#include <iostream>

int main()
{
  // ...

  std::cout<<"Press [Enter] to continue . . .";
  std::cin.get();
}

>But it's not so bad to use conio.h
Yes, it is. You just don't realize it because you're a beginner. :icon_rolleyes:

[1] For the most part. There is a sticky thread that discusses further issues if the input stream needs to be flushed.

JasonHippy commented: It's a fair cop guv! I put my hands up to points 2 and 3...I was wrong! ;) +1
Narue 5,707 Bad Cop Team Colleague

>So the iostream allows for keyboard input
At the risk of giving you too much information, there are several stages that your code goes through from source to executable. Here are the stages (bird's eye view):

  1. Source file: This is the stuff you write, exactly as you write it.
  2. Translation unit: This is the result of running the preprocessor to completion (merging headers into the source file, expanding macros, etc...). The preprocessor handles this step, obviously.
  3. Object file: Processing the translation unit produces machine code that isn't necessarily executable, but can be combined with other object files to create an executable. The compiler handles this step.
  4. Executable file: One or more object files are linked together such that external references (one translation unit using stuff from another) are resolved. The linker handles this step.

<iostream> is what C++ calls a header (not a header file, because headers need not be stored on the file system). Headers are used to supply declarations for code that's defined in a separate object file. These declarations are necessary for the compilation step to complete successfully. Without them, the compiler will complain that you're using unknown names and fail long before you get to the linker.

The <iostream> header contains declarations for the standard stream objects you'll be using at first (cin, cout, cerr, clog), and their wide counterparts (wcin, wcout, wcerr, wclog). Those objects are the interface to the standard streams. Note that I didn't mention a keyboard yet. …

Narue 5,707 Bad Cop Team Colleague

Being busy and lack of interest conspire to keep me away. Rest assured, when(if) I return full force, you can look forward to old school Narue replies.

jephthah commented: yay! +0
Narue 5,707 Bad Cop Team Colleague

Sculpting, flower arrangement, ballet, and firework pyrotechnics. I would like to know the difference between these listed.

Narue 5,707 Bad Cop Team Colleague

>why would you bad mounth someone for asking a questions.
Can you be any more melodramatic, Mr. Drama Queen? As much as goody goodies like you want the world to run on sunshine and fairy dust, negative reinforcement is the quickest way to alter undesirable behavior. Compare and contrast:

Exhibit 1: "I posted my homework problem for someone else to do and went away for an hour to watch TV. But nobody has answered. I guess they didn't see it. Hey, I'll just do it again and again until they do notice."

Exhibit 2: "I posted my homework problem for someone else to do and went away for an hour to watch TV. Now my post has twenty down votes. I guess I shouldn't have done that. Maybe I should read the rules and learn more about how to post on this forum."

Exhibit 3: "I posted my homework problem for someone else to do and went away for an hour to watch TV. Now my post has twenty down votes. These losers won't help me cheat. I'm outta here."

Personally, I prefer the result in exhibit 2, but running leeches off before they suck us dry as in exhibit 3 isn't a bad deal either. As much fun as verbal abuse is, down votes and negative rep help us achieve the same goal without it.

Narue 5,707 Bad Cop Team Colleague

If the bug is squashed, are you going to complain that we're not ensuring backwards compatibility with all your code tags?

Um, you fail. This isn't a bug, it's documented behavior that's been in place for years. You may as well just call it what it is: changing basic functionality of the forum, retroactively altering all of our posts, screw backward compatibility, and tough shit if we don't like it.

Honestly, I don't think the change itself is that big of a deal. But blaming us for not using the forum as it was "intended", despite the fact that we used it as it was documented? That's a new low.

Narue 5,707 Bad Cop Team Colleague

>I don't really see your point....
That much is obvious.

>Is your point that is not 100% the standard?
My point is that it could potentially be the cause of your problem because a compiler is not required to support it. Didn't I make that clear already? Technically it's undefined behavior and when commenting out random lines makes the code work, undefined behavior is the most likely culprit.

>I can live with that
I won't hold that against you. Personally, I prefer the option that's guaranteed to work in all cases rather than the option that will only work on the version of the compiler that I'm currently using.

Narue 5,707 Bad Cop Team Colleague

>However, using code tags for something outside of code to achieve
>a visual effect as a result of the current way code tags happen to be
>handled cannot ever be guaranteed in the future.

Translation: "Bite me. You didn't use tags for the narrow purpose they were designed, so you don't have a right to complain when I change their behavior".

That's all well and good if you're a cruel dictator, but it's not generally a good idea to make your members angry. Daniweb isn't the only tech forum out there, after all, and the ones most likely to be annoyed by this change are the ones who provide you with the most value.

>It is almost like exploiting the current system to do something it isn't designed to do
IIRC, code and quote tags were used to "exploit" the system because there wasn't any other way to achieve anything remotely like the presentation we wanted. Perhaps instead of giving us the proverbial finger, you could incorporate something into the system so we don't need to exploit it?

Dave Sinkula commented: :) +0
Narue 5,707 Bad Cop Team Colleague

Methinks this poll is biased. You're missing a few moderators, including our illustrious super mod...

Narue 5,707 Bad Cop Team Colleague

>so tell me when u ll start to learn me ???????? i m wating
I'll learn you good. Start by not being so impatient. Everyone has to start from nothing and work their way up to something. Being given solutions doesn't help you learn nearly as much as working your way through to your own solution.

>n what do u mean by provide code??
He means try it first on your own before begging for help. I can guarantee that when (or if) you get into the real world as a programmer and try that BS, you'll be told to do your damn job and stop whining.

Narue 5,707 Bad Cop Team Colleague

>i spent lot of time in googling but couldnot get it.
Hmm, perhaps that's because it's copyrighted and any free PDF you find is illegal? If you want the book that badly, go buy it. If you can't afford it or don't want to buy it, then do without. It's that simple. Nobody here is going to help you break the law.

Narue 5,707 Bad Cop Team Colleague

>Please help me find the mistake!
I suspect the mistake is a complete failure to study whatever book on C you have. Instead of trying to finish this exercise in one swell foop, perhaps you should be writing a simple skeleton that passes structures around. At least that way you'll fail on fundamental concepts much sooner and will have an easier time sorting things out.

Narue 5,707 Bad Cop Team Colleague

Know-it-all douchebags don't usually have a special place in my memory unless they were especially fun to smack down, but yes, I do vaguely remember you. ;)

Narue 5,707 Bad Cop Team Colleague

>Even though I am 8
If you're 8 years old then you are in violation of Daniweb's policies (members must be at least 13 years of age). Therefore, I'll report this thread so that you can be properly banned for the next five years.

Nick Evan commented: Haha :) +10
pspwxp fan commented: pwnt :D +1
Narue 5,707 Bad Cop Team Colleague

Now that you've added this extra statistic, it would be nice to also include a search filter based on votes. For example, say I want to search for all of my posts that have been downvoted, or posts with more than one upvote. Currently I have to do a search and then manually step through the results and eyeball the votes, which is somewhat tedious.

p.s. A limit of 500 results on an individual search is quit limiting when at this point many of us have thousands of posts.

Narue 5,707 Bad Cop Team Colleague

>I don't understand why you're leaving after having a post deleted.
Just another childish person stomping off in a huff when things don't go his way. The best way to deal with such pitiful theatrics is to ignore them.

Narue 5,707 Bad Cop Team Colleague

>Please stick to the topic.
I never went off topic. You have a brace mismatch, and the reason you have it is because your formatting is atrocious. Fix the formatting and you will see the problem.

Im new to C++ and knows nothing.
Clearly. But you know enough to write that mess, so you should know enough to format it like the books or tutorials you're following to learn C++. We don't format our code just to make it look pretty, we format it to make errors stand out. This is a lesson you need to learn, as early as possible, and I'm not afraid to beat it into you.

Im not bashing him. He started.
Your first mistake is thinking that I was bashing you. You're not important enough for me to bother. Just another noob who gets all insulted and defensive when I tell him that his code sucks. I haven't even gotten into the other problems with your code, and I probably won't if each issue is going to be a battle against your frail little ego.

Im just here asking not to be insulted.
Sorry dude, but bad code is bad code. If you're insulted by me pointing out your bad code, you have insecurity issues that need to be addressed.

Nick Evan commented: Subtle and friendly as always! :) +29
Narue 5,707 Bad Cop Team Colleague

I suspect that if you fixed that piss poor formatting, you would easily find the problem. But noooo, you had to make it harder on yourself by writing code in a manner that hides bugs.

Salem commented: And this is the improvement ;) +36
Narue 5,707 Bad Cop Team Colleague

This code demonstrates AVL insertion and deletion. The code was originally written in C by myself a little while back for a tutorial. The translation to Java was fairly trivial, and to add a little excitement I even threw in a few generics. Yes, I'm aware of this line:

tree.data = heir.data;

But thank you for your concern.

There are two significant differences between the C code and the Java code. First, In Java, boolean values cannot be used in integral context. Therefore my yummy design in C is a little bitter in Java because I had to either use the conditional operator to get my logical NOT, or duplicate a lot of code for symmetrical cases. Second, because Java Generics don't lend themselves well to arrays, I chose to use the ArrayList collection rather than a built in array for the links as I did in C.

All in all, a mildly interesting diversion, and now Daniweb has an AVL implementation to its name. :-)

tux4life commented: Great to 'C' you writing in another language than C/C++ ;) +13
Narue 5,707 Bad Cop Team Colleague

Insertion sort, Selection sort, Bubble sort, Shell sort, Quicksort, and Heapsot. All optimized and ready to be experimented with. This is the framework for a Java application that speed tests various sorting algorithms (because there's usually little need to write one's own in production programs). Several popular algorithms were left out because I didn't feel like implementing them. Included in this list are counting sorts, radix sorts, merge sorts, and the introsort. All are interesting, but I get bored quickly.

Narue 5,707 Bad Cop Team Colleague

This quicksort implements the basic recursive algorithm with three improvements. The first improvement is choosing the pivot based on the median of three values in the list to be sorted. This minimizes the chances of a worst case scenario. The second improvement speeds up the algorithm by termination when subfiles of a certain size are reached. At that point continuing the recursion is not as effective as calling insertion sort on the almost sorted list. The last improvement protects against worst case behavior if there are large numbers of duplicates on the list by partitioning three ways instead of two: all items that are smaller than the pivot, all items that are equal to the pivot, and all items that are greater than the pivot.

One more improvement can be made to bring this implementation to production quality. It must be generalized for any type by accepting pointers to void and a comparison function.

one might also remove tail recursion, but on modern machines this isn't nearly the issue that it once was.

pavan_teja commented: This is great work!!! +0
Narue 5,707 Bad Cop Team Colleague

>So if you did mean well.. and even if it came out in a bent, skewed
>and poorly communicated way, well thank you I do actually appreciate that.

Too little, too late, and wording it like your misunderstanding is my fault. It's a wonder you have any friends at all. By the way, if you were truly interested in peace and happiness, you should have taken more time to understand my post before mouthing off.

You fail. Plonk.

Narue 5,707 Bad Cop Team Colleague

If you had read the "bla bla bla" part that you so rudely snipped out to make me look like the villain, I was agreeing with you that you were not in the wrong. If that's what I get for trying to help you, you can just piss off. Jerk.

I was going to help you with your C question, but now I won't. Congratulations, you're alienating even your allies now.

Narue 5,707 Bad Cop Team Colleague

>My goal is to "master" C++.
That's a nice goal, but don't plan on actually attaining it. I doubt there's anyone in the world who's mastered C++. There's just too much involved, too many nuances. But you can certainly be a C++ badass. That's more than possible given a decade or so of hard work.

>My question is how much more do I have to learn to be like you?
Quite a lot, to be honest. But it's the journey that you should be looking forward to.

>There are times I felt stupid or I was just impatient to
>read thoroughtly, or the book is just too confusing.

Feh, get used to it. All programmers of any ability spend most of their time in a state of confusion because they're always pushing themselves.

Democles commented: I liked the post it was nice and welcoming. +1