Instead of
while(vec.size() < 65536 && (ch = stream.get(), !stream.eof()))
vec.push_back(ch);
Is there any elegant way of doing that?
Type: Posts; User: RichSelian
Instead of
while(vec.size() < 65536 && (ch = stream.get(), !stream.eof()))
vec.push_back(ch);
Is there any elegant way of doing that?
clang++ can compile the following code without any error and warning, but g++ always gives me the error "no matching call ..."? Is it a bug of g++ or kind of extensions of clang++?
#include...
Under linux, you can use getenv() in stdlib.h to retrieve the environment variable "HOME". But I don't know whether it works under windows.
The code is here. C Mozilla Pastebin - collaborative debugging tool
I'm writing heap sort as an inline function and a macro with the same implementation. In my test, the inline function runs much...
#define cmp(x, y) ((x)-(y)); This implementation may course overflow and return the wrong result.
Any better idea? or am I going to write ugly int_cmp() short_cmp() char_cmp()/... using the inline...
You can simply modify the swap function in the sorting procedure.
But why not use something like a structure?
I want such a macro in my project: cmp(x, y) returns a positive number when x > y, a negative number when x < y, and 0 when x == y. of course I know the simplest way:
#define cmp(x, y) (((x) >...
working under linux...
I'm thinking of implementing exception handling in C and extractly I have written a simple one. But it's not threaded-safe. Can you have me fix it, or is there any similar implementation for...
Yes, but you use recursion, that will slow down the speed.
My tree will become unbalanced after times of deletion and one search operation will cost O(n), but searching a deep node will restore...
But it's quite faster than a normal avl tree. My balancing operation is top-down and it doesn't require any recursion or parent pointers, so it can save a lot of time and memory space.
The condition...
This is a simple test code:
// #############################################################################
// # FileName: topdown.c
// # Author: Zhang Li, CS0901, HUST
//...
I wrote this code just for fun, but then I found that it's performance is excellent in both speed (faster then std::map) and memory space, and it's very easy to implement. But I lack some mathemetic...
I use my own stack instead of the system's and now it works, thank you!
I create a top-down splay tree but don't know how to destroy it? Since the tree can be very deep, the recursive destruction sometimes cause stack overflow. How can I get it work without changing the...
Of course I know that. But I'm trying generic programming in C so I need macros to do that.
For example, now I have an implementation of avltree and want to use it as a dictionary. I have to write a...
That may be a little crazy, but I want to implement syntax-candy like this:
MAPITEM_TYPE(int, const char*) mapitem;
MAPITEM_KEY(mapitem) = 1;
MAPITEM_VAL(mapitem) = "Hello";...
int main()
{
struct
{
int m_aa;
int m_bb;
} a = {0, 1};
struct
{
You know every types of pointers are the same -- they are all unsigned integers. So you can convert them to whatever types you want. And using void* seems better here.
I have a recursive verion which costs just 0.7sec sorting 100,000 integers. This non-recursive version just replace the system's stack with its own, then it costs almost 1.5sec.
The non-recursive...
that comparing function is foolish. it returns 1 when the last elements is equal.
// the correct one:
int equal_arrays(int a1 [], int a2 [], int n)
{
int i, result;
for (i=0; i<n; ++i)...
grades[i+1] overflowed when i == 99
I implemented a macro of the non-recursive quicksort, but I found it much slower than I expected (it's slower than non-recursive mergesort). Is the non-recursive quicksort always slow? or I made some...
COMPRESS.C says "This implementation uses multiple binary trees to speed up the search for the
longest match", but it didn't describe how to construct those trees and how they work.
The algorithm needs to match a string in (4096*16=65536) strings, but it seems it uses only 4096 nodes for the tree. I just cannot understand how he can do that.