[Solved] Implementing a graph in either C++ or Java [closed]

[ad_1] Firstly, language choices aren’t the most massive issue in the world, in my opinion. Unless you have a requirement to use a specific language or on portability, using either C++ or Java will be sufficient. Having said that, your question seems somewhat homework-ish. Are you using Prim’s algorithm for your MST implementation? As other … Read more

[Solved] Receiving an “Error: expected an identifier” on C++ for “==”

[ad_1] if (f_in); std::ifstream == int NULL); You could rewrite this as this: if (f_in) ; std::ifstream == int NULL); And you can see that this doesn’t really make sense. Maybe you meant: if (!f_in) { fprintf(stderr, “Can’t open input file in.list!\n”); exit(1); } Or if (f_in == NULL) { fprintf(stderr, “Can’t open input file … Read more

[Solved] Checking if a number is a Simber

[ad_1] Your code has compilation errors. ^ is Binary XOR Operator. You can’t expect it to produce pow(10,i). So replace nmbrs.push_back(((n/10^i) % 10); with nmbrs.push_back(((n/pow(10,i)) % 10); When I was able to remove the compilation errors, i realized your code has logical errors too. As your given definition of simber, int is_simber(int n) should be … Read more

[Solved] Adjacency List for Graphs in C

[ad_1] Your program is causing memory leak. You should use an array of ADI*, not an array of ADI, to store what is returned from adjancencyList(). Using subscripting looks better than incrementing in this case. One more tips is that A = &( A[0] ); does virtually nothing. Also note that they say you shouldn’t … Read more

[Solved] Malloc , Realloc , Memset : Struct pointers , arrays of char, int

[ad_1] Error was in v_push_back implementation : v->e_array = check_a(memcpy((void*)((char*)v->e_array + (v->no_e * v->e_sz)) ,new_val, v->e_sz)); //pointer has not to be saved check_a(memcpy((void*)((char*)v->e_array + (v->no_e * v->e_sz)) ,new_val, v->e_sz)); Because memcpy returns a pointer , in this case, to the last element of the array so we would have lost access to all previous memory … Read more

[Solved] I want to know something about pointers in C

[ad_1] ++ has a higher precedence (meaning it binds to p tighter) than * therefore *p++ is equivalent to *(p++). Something similar to this is the difference between *p[] and (*p)[]. [] has a higher precedence than * therefore *p[] is equivalent to *(p[]) which makes a list a pointers but something like (*p)[] explicitly … Read more

[Solved] How do I get this constructor to work?

[ad_1] Removing all the irrelevant noise here seems to be (one of) your problem(s): class WeatherForecaster { public: // you declare a constructor that does not take any variables WeatherForecaster(); // … }; Does the definition match? // you define a constructor that takes three and a half million variables!!! WeatherForecaster::WeatherForecaster(string d, string fd, int … Read more

[Solved] Why this code is not giving right result for large arrays? [closed]

[ad_1] Here is the correct code #include<stdio.h> #include<stdlib.h> int main() { int t,T,n,i,j; long long int count,k; scanf(“%d”,&T); int *c = calloc(1000000,sizeof(int)); for(t=0;t<T;t++){ scanf(“%d”,&n); int temp; count =0; for(i=0;i<n;i++){ scanf(“%d”,&temp); c[temp-1]++ ; } for(i=0;i<1000000;i++){ if(c[i]>1){ k = c[i]; count+= k*(k-1); } c[i] = 0; } printf(“%lld\n”,count); } return 0; } Changes : Used calloc to … Read more

[Solved] Can we use classes as header

[ad_1] In the example there is used a header as header.:) That is the class definition is placed in separate header sales_item.h that is included in a module where the class definition is used. The class itself is named as Sales_item. 5 [ad_2] solved Can we use classes as header

[Solved] How to match two values in an array?

[ad_1] Why use arrays when you can use a sorted dictionary? take a look at this code example: SortedDictionary<int, int> sd = new SortedDictionary<int, int>(); sd.Add(1, 54); sd.Add(5, 12); sd.Add(3, 17); sd.Add(9, 1); sd.Add(2, 44); MessageBox.Show(“First: ” + sd[sd.Keys.ElementAt<int>(0)].ToString() + “\nLast: ” + sd[sd.Keys.ElementAt<int>(sd.Count-1)].ToString()); [ad_2] solved How to match two values in an array?