structure

implement 2d range tree c++

倖福魔咒の 提交于 2019-12-11 13:52:17
问题 I have been trying to understand range tree for some time, but i still can't understand it. Can someone explain it to me with an implementation, because i want to use it to solve 2D RMQ, i know segment tree, and my teacher tell me range tree is similar to 2d segment tree, but i just can't think how the space complexity can be less than n^2 like 2d segment tree. I'm not sure about this, but is it true that, it's like merge sort, so the memory will be less than n^2 using vector void merge

error C2512: no appropriate default constructor available (not classes)

不羁岁月 提交于 2019-12-11 13:48:31
问题 I'm starting out with structures, and I'm having problems dynamically allocating my structure array. I'm doing what I see in my book and on the internet, but I can't get it right. Here's both full error messages: C2512: 'Record' : no appropriate default constructor available IntelliSense: no default constructor exists for class "Record" #include <iostream> #include <string> using namespace std; const int NG = 4; // number of scores struct Record { string name; // student name int scores[NG];

Unable to pass the generated values from a for loop to a structure

倾然丶 夕夏残阳落幕 提交于 2019-12-11 13:44:22
问题 As per my earlier asked question , i am trying to pass values generated from the code i.e. hashname(variables which are generated in the forth loop, combination of a-z, a four character string) to a structure member, using this code. vcd_xyz[4]='\0'; count = 0; for(int i=0;i<26;i++) { vcd_xyz[0] = 'a'+i; // printf("%d generated variable is initial is = %c \n",i,vcd_xyz[0]); for(int j=0;j<26;j++) { vcd_xyz[1] = 'a'+j; // printf("%d generated variable is = %c \n",j,vcd_xyz[1]); // puts(vcd_xyz)

Using realloc in dynamic structure array

半世苍凉 提交于 2019-12-11 13:41:37
问题 I am trying to use realloc to dynamically create instances of a struct, filling it with data from a temporary structure as I go. The program crashes when it reaches the line to malloc a pointer of the structure a second time but I am not sure how I should structure this function. I have the following code: #define MAX_STRING 50 struct data { int ref; int port; char data[MAX_STRING+1]; }valid, invalid; void read_file(FILE *file); void validate(struct data* temp); int g = 0; int main(){ char

Structures with conditional members

最后都变了- 提交于 2019-12-11 11:54:59
问题 I'm trying to build a structure in VB to allow me to both store and parse an IP/UDP based message that I'm receiving as ASCII encoded HEX. The trick is that after I get past the IP header and the UDP header the data that follows after is of a variable structure type. By that I mean that there is a basic initial message structure that has data in specific fields... two thirds of which are optional... but then the actual data, the real meat of the transmission, is in one of 15 different message

Boost Serialization : How To Predict The Size Of The Serialized Result?

一笑奈何 提交于 2019-12-11 09:38:20
问题 I use booost serialization that way : Header H(__Magic, SSP_T_REQUEST, 98, 72, 42, Date(), SSP_C_NONE); Header Z; std::cout << H << std::endl; std::cout << std::endl; char serial_str[4096]; std::memset(serial_str, 0, 4096); boost::iostreams::basic_array_sink<char> inserter(serial_str, 4096); boost::iostreams::stream<boost::iostreams::basic_array_sink<char> > s(inserter); boost::archive::binary_oarchive oa(s); oa & H; s.flush(); std::cout << serial_str << std::endl; boost::iostreams::basic

Arrays in structures

倖福魔咒の 提交于 2019-12-11 08:43:13
问题 I'm new to C and having a problem with array types when embedded in structures. The following is an example of my issue: typedef struct { double J[151][151]; } *UserData; static int PSolve(void *user_data, N_Vector solution) { UserData data; data = (UserData) user_data; double J[151][151]; J = data->J; /* Solve a matrix equation that uses J, stored in 'solution' */ return(0); } When I try to compile this I get error: incompatible types when assigning to type ‘double[151][151]’ from type

what is the cause of this error: Structure required on left side of . or .*?

橙三吉。 提交于 2019-12-11 08:14:28
问题 typedef struct tsk{ int x; int n; }TSK; TSK trd[MAX]; main(){ while(life!=0){ randomize(); for(i=0;i<MAX;i++){ trd[i].n=rand()%40+10; if(trd[i].n<10||trd[i].n>45) trd[i].n=rand()%40+10; trd[i].x=25; } for(m=0;m<MAX;m++){ gotoxy(8,m);printf("%c%c",23,23); gotoxy(7,m);printf("%c",17); gotoxy(46,m);printf("%c%c",23,23); gotoxy(48,m);printf("%c",16); } for(j=0;j<MAX;j++){ if(life==0) break; gotoxy(1,1); insline(); gotoxy(trd[j].n,1); printf("%c",3); trd[j].x--; gotoxy(ply,25); printf("%c",1);

Why this union is deleting the 1st records in arrays in the c code?

吃可爱长大的小学妹 提交于 2019-12-11 07:45:58
问题 Here is one of my header file which consists of a union template with 4 different structures. #define MAX 3 union family { struct name /*for taking the name and gender of original member*/ { unsigned char *namess; unsigned int gender; union family *ptr_ancestor; /*this is a pointer to his ancestors details*/ }names; struct male /*for taking the above person's 3 male ancestors details if he is male*/ { unsigned char husb_names[3][20]; unsigned char wife_names[3][20]; unsigned int wife_status[3

Properly removing elements from linked-list? Memory errors with pointers

别来无恙 提交于 2019-12-11 07:32:36
问题 I'm implementing a hashtable that has a remove_entry function as well as a clear_table function. Right now I'm getting memory read errors pertaining to the remove_entry function. And help would be greatly appreciated These are my structures: typedef struct bucket { char *key; void *value; struct bucket *next; } Bucket; typedef struct { int key_count; int table_size; void (*free_value)(void *); Bucket **buckets; } Table; Here's my function: int remove_entry(Table * table, const char *key){