- Strength to Increase Rep
- +12
- Strength to Decrease Rep
- -3
- Upvotes Received
- 181
- Posts with Upvotes
- 129
- Upvoting Members
- 69
- Downvotes Received
- 13
- Posts with Downvotes
- 11
- Downvoting Members
- 9
436 Posted Topics
Re: [QUOTE]what is the time cost of the actual re balancing of the tree[/QUOTE] It depends on how the algorithms are implemented, but ideally for insertion the cost of rebalancing is constant. Only one part of the tree will ever be out of balance and at most two rotations will bring … | |
Re: I never liked the term "Self Referential Structure" because it implies that objects of the structure always refer to themselves. A self referential structure is better called a recursive structure. If the pointer is not NULL, it points to another instance of the structure. The null pointer is a base … | |
Re: [QUOTE=firstPerson;947801]There is also cout.width(...).[/QUOTE] [ICODE]cout.width()[/ICODE] is not sticky. You need to call it for every object that gets printed, so code like this will only right justify the first string: [code=cplusplus] cout.width(30); cout << "right justified\n" << "left justified\n"; [/code] To justify both strings, you need to split the output … | |
Re: Have you read [URL="http://www.beej.us/guide/bgnet/"]Beej's guide[/URL]? | |
Re: jephthah's way is the safest and most portable once you fix the nonportable assumptions: [code=c] #include <stdio.h> #if __STDC_VERSION == 199901L #include <stdint.h> #else /* change to fit the compiler */ typedef unsigned char uint8_t; typedef unsigned long uint32_t; #endif #define IPV4 #if defined(IPV4) #define NBYTES 4 #elif defined(IPV6) #error … | |
Re: [QUOTE][CODE]temp1 *maintemp1;[/CODE][/QUOTE] temp1 is a template class. The error means exactly what it says, and you should add a template argument list. Maybe [ICODE]temp1<test3>[/ICODE]? | |
Re: Base means the longest sequence of fundamental digits before reaching 10. 10 is not limited to the decimal counting system, it is used in other bases to mean one more than the base: Base 10, decimal: 0 1 2 3 4 5 6 7 8 9 10 Base 8, octal: … | |
Re: [QUOTE]do you know any method in which to draw hearts all over the screen in C++?[/QUOTE] I sure do: [code] #include <iostream> int main() { for (int x = 0; x < 1000; ++x) std::cout << "<3"; } [/code] :D | |
CSV is more than just comma delimited fields. There are quoting and white space rules too. This is a short function as an example of a complete way to read CSV records line by line. | |
Re: [QUOTE]i can't get how can i use that in a program .[/QUOTE] alloca() is used just like malloc(). The difference is how they work under the hood. [QUOTE]and what is the advantage of such a function.[/QUOTE] [LIST] [*]alloca() is faster because it just needs to adjust the stack pointer. malloc() … | |
Re: [QUOTE]then it would be like if-else if internally.[/QUOTE] [QUOTE]but here it is given as it uses jump tables [/QUOTE] I think compilers commonly use jump tables for a tight range of cases and compares for wider ranges. This switch would probably use a jump table: [code] switch (condition) { case … | |
Re: [QUOTE]readb has declared under public section but am unable to access that through the derived class object d. d.readb();//is ambiguous[/QUOTE] read() is ambiguous, readb() should not be. You created the [URL="http://en.wikipedia.org/wiki/Diamond_problem"]Diamond Problem[/URL] where the most derived class has two copies of the same base object. Virtual inheritance fixes this problem … | |
Re: [QUOTE]When i remove the root of the binary tree and I view the binary tree in In-Order Traversal, my program will stop running.[/QUOTE] Then you are not resetting the links the way they should be. Removing the root means replacing the root with either the inorder predecessor or successor. Something … | |
Re: Technically all you need is a stack to store the nodes needed to get back to the nearest root and traverse the other subtree. So the memory cost is O(logN), not O(N), because the size of the stack has at most as many nodes as [ICODE]height(tree)[/ICODE]. The only way I … | |
Re: [QUOTE]Can anyone give me some ideas on how to find the middle value between 3 numbers.?[/QUOTE] Assuming it is always 3 numbers, and what you want is the median value, here is a simple way. Find the maximum then the minimum and the one you didn't pick is the median. … | |
Re: [QUOTE]Would anyone like to share their tips & tricks for debugging functions & whole programs in C++. [/QUOTE] Learn how your computer works! :) I found that understanding the machine and things at a lower level like assembly and how the OS manages programs/memory really helped my debugging. It also … | |
The forum is buzzing with questions about tokenizing a C++ string. This is a short function that does it and returns a vector of the tokens. As an option, the delimiter string can represent either a multichar delimiter or a collection of single char delimiters: [code] // multichar delimiter == … | |
Re: [QUOTE]if i compare number of his posts or reputation points or solved threads, i think Ramy or Scott(sknake) must be granted these before than him.[/QUOTE] If the criteria for being featured are post count, solved thread count, and reputation points then there are a lot of people in line before … | |
Re: [QUOTE]Don't use Turbo C[/QUOTE] Why not? | |
Re: Does your AvlNode class have a public default constructor, public destructor, and public assignment operator? Those are the requirements for storage in a container class. | |
Re: [QUOTE] *Implementation of the Traveling Salesman Algorithm on Networking Systems. *Graph Traversal System Using Best Path Method . *Analysis on the Different Advanced Algorithms *Implementation of the Closest Pair Algorithm on Networking Systems *Comparative Study on the Efficiency of Sorting Algorithms[/QUOTE] These have been done to death. If you are … | |
Re: [QUOTE]Newbies not using code tags are a huge issue for us, and we finally made some successful progress[/QUOTE] It must have been a sad state of affairs before that progress, because almost none of the new members use code tags in the C and C++ forums now. | |
Re: The algorithm is the same as with a binary tree. The only difference is you loop through the vector to find a matching key and then loop through the links and recursively traverse each one in turn. | |
Re: Typically the two options for a case like this are a count argument and a sentinel argument: [code] #include <stdio.h> #include <stdarg.h> /* gets a count of arguments */ void TestCount(int x, int n, ...) { va_list args; va_start(args, n); printf("%d: ", x); while (--n >= 0) printf("%-3d", va_arg(args, int)); … | |
Re: What do you mean by a points system? The whole idea is pretty vague. | |
Re: You do need to do an fseek to that location, but not because C uses separate read and write pointers. The standard says that when switching between read and write mode on a stream, there needs to be a flush or seek between them. So you would read to the … | |
Re: [QUOTE]..or may be I am missing some option, in witch case, it should be a lot more visible than it is... I couldn't find it ;-) [/QUOTE] I can go to the Delphi forum, then under the Related Forum Features box on the right there is a direct link to … | |
Re: [QUOTE]can somebody explain the behaviour of the statement printf("%d");[/QUOTE] Undefined. In practice it will probably print whatever is next in the stack and potentially corrupt the rest of your program by moving the stack pointer in an unexpected way. | |
Re: Do not write the line in the first place and you do not have to delete it. :) | |
![]() | Re: [ICODE]input == depth[/ICODE] will happen for every node at that depth. You only want to print the total after the function returns instead of inside the recursive function. A reference parameter would be better suited to that: [code] #include <iostream> struct treeNode { int data; treeNode* left; treeNode* right; treeNode(int … |
Re: [QUOTE]its already available for free on internet.[/QUOTE] Not legally, AFAIK. Any that you find are pirated and in breach of copyright. You can contact Addison-Wesley and ask them to be sure, but I think you will get the same answer. | |
Re: C++ has two kinds of strings. The strings inherited from C are char arrays with a terminating '\0' character. All of the rules for arrays apply, which means you can only return a pointer to the array somehow. But if the array is local to the function returning it, you … | |
Re: [QUOTE]getch();[/QUOTE] This may or may not work. getch() is not a standard function and not all compilers implement it as an extension. If the only goal is to keep the window open, any blocking read will do: [code] #include <iostream> int main() { std::cout << "Hello world!\n"; // blocking read … | |
Re: The simplest way to adjust the range of rand() is with the modulus operator: [code] #include <iostream> #include <cstdlib> int main() { for (int x = 0; x < 20; ++x) { std::cout << (std::rand() % 900 + 100) << '\n'; } } [/code] I am sure someone will chime … | |
Re: [QUOTE]Can I enable/disable an #ifdef based on a specific condition?[/QUOTE] Yes, but only if the condition is available at compile time. In your case the value of i is a run time quantity, so you cannot use it with the preprocessor. I think what you really want is an [ICODE]if[/ICODE] … | |
Re: [QUOTE]would the restore code go in the trees constructor or do i need a seperate function to initialize all the nodes?[/QUOTE] I would put it in a separate constructor, as well as a public method. The actual implementation could be in a private method that is shared between the two. … | |
Re: [QUOTE]I just cant seem to fathom the last part of each line is being completely ignored...[/QUOTE] I know the answer to this problem because it is a problem I create myself on a regular basis. :) On the last token, [ICODE]finish [/ICODE]will be [ICODE]string::npos[/ICODE]. After the last token, [ICODE]start [/ICODE]should … | |
Re: [QUOTE]i have not yet learned the code to do it and dont want to wait.[/QUOTE] You can learn on your own how to do it and not have to wait for your class to catch up. Then again, patience is an important trait for a programmer to have. Rushing through … | |
Re: [QUOTE][CODE]#include <assert.h> #include <complex.h> #include <ctype.h> #include <errno.h> #include <fenv.h> #include <float.h> #include <inttypes.h> #include <iso646.h> #include <limits.h> #include <locale.h> #include <math.h> #include <setjmp.h> #include <signal.h> #include <stdarg.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <wchar.h> #include <wctype.h>[/CODE][/QUOTE] It is always good … | |
Re: The second menu is legitimate. When you typed something for scanf() to read, you also pressed [Enter], right? That [Enter] is a character too, and it is stored in the stream as '\n'. The first menu is the one you want, but because there is another character ready to be … | |
Re: [QUOTE]where is this function and how is it called ?[/QUOTE] It is done by the C runtime. The same code that calls main() collects arguments from the command shell and parses them into an array of char pointers. | |
Re: There are left over characters in the stream that cin.get() is reading immediately. It is not blocking, so the program ends immediately and I assume the window is closing so you cannot see the output. Try this: [code] #include <iostream> using namespace std; int main() { int length; // this … | |
Re: I/O is kind of complicated in C. Can you list out your questions so that it is easier to answer them? I will be happy to give you all of the details you want, but right now it feels like I would end up writing a small book. | |
Re: Your search always starts from position 0, that is why tokens are being duplicated. You need to skip over the extracted tokens as you go. Something like this: [code] #include <iostream> #include <string> #include <vector> int main() { using namespace std; string const punct = "+-*/<=!>{()};,"; string str = "dressed(with)"; … | |
Re: Do not forget to enter curses mode before using getch() and leave curses mode when you are done: [code] #include <ncurses.h> int main() { initscr(); printw("Enter a character: "); printw("You entered '%c'\n", getch()); refresh(); endwin(); return 0; } [/code] | |
Re: To add to dkalita's reply, the array decaying into a pointer rule only applies to the first dimension. The pointer version of your 2D array function parameter is [ICODE]int (*)[MAX_COL][/ICODE]. You can change your function in either of these two ways: [code] void fnGetMatrix(int aiMat[][MAX_COL,int *iNoOfRows,int *iNoOfCol) [/code] [code] void … | |
Re: [QUOTE]So at what point I have to delete this pointer?[/QUOTE] As long as you have a copy of the pointer that was returned by [ICODE]new[/ICODE], you can delete it. You said that the pointer is stored in another object, so that object's destructor would probably handle the deletion. Though that … | |
Re: Do a Google search. You can download the runtime as an redistributable package from M$. |
The End.