How to pass vector's cell to a function in C++?

I want to make a function that takes an object from a vector's cell and modifies it. First I need to pass this cell by reference to the function and I can not do it. void circleChoiceOne(Circle& object); vector<Shape*> shapeArr; int main()...
more »

2017-01-13 16:01 (2) Answers

C++ sort vectors time complexity

Suppose I have a vector<vector<int>> L with N vectors, and total number of ints summed across all vectors is at most M. What is the tightest time complexity of the standard C++ sort sort(L.begin(), L.end())? The vector<int> compari...
more »

2017-01-12 23:01 (2) Answers

Multidimensional data type in Scala

I have a generic class, which is constructed from multi-dimensional data (i.e. n-dimensional Ararys or Vectors). In this case, I would like the class to be instantiated by one type only (e.g. Vector), aside from its dimensionality (Vector[Vector[T]] ...
more »

2017-01-09 17:01 (1) Answers

Numpy: Sparsify vector

Let's say I have a numpy vector with shape (1,4) [[-0.0397072 0.43854361 -0.86175428 -0.25195716]] The question is very simple: I would like to add "n" zeros to this vector: [[-0.0397072 0.43854361 -0.86175428 -0.25195716 0 0 0 0]] If you c...
more »

2017-01-01 21:01 (0) Answers

how to fill in values in a vector?

I have vectors in R containing a lot of 0's, and a few non-zero numbers.Each vector starts with a non-zero number. For example <1,0,0,0,0,0,2,0,0,0,0,0,4,0,0,0> I would like to set all of the zeros equal to the most recent non-zero number. I....
more »

2016-12-31 00:12 (3) Answers

C++ deleting from a vector of emails

I've emails loaded from a text file into a vector and I want to allow the user to enter an email of a sender and find that in the vector and delete that object, but for some reason i'm getting an error. here is the function void deleteEmail(vector&...
more »

2016-12-20 03:12 (1) Answers

initialize vector in class

I have the following problem. I have a class, say class MyClass{ public: class MyNumber; MyClass(char const *filename); class MyNumber{ public: MyNumber(int n) : n(n) {} private: int n; }; private: std::vector<MyNumber> ...
more »

2016-12-09 19:12 (1) Answers

Function to replace certain values in a vector

Say I have two vectors: a<-c(6,6,NA,NA,9,9,8,NA,NA,7,NA,NA,NA,NA) b<-c(NA,NA,NA,NA,NA,NA,NA,NA,NA,8,NA,5,7,NA) If there is any increase in the vector, I change the values to NA. Say, in vector a, fifth value is 9, increase from last value 6...
more »

2016-12-02 20:12 (1) Answers

Search for characters string in a DNA sequence

I'm trying to look at certain patterns of nucleotide in a gene sequence. I've just done read.table to get it in but I've tried converting it to vectors and data frames as well. How do I search for a pattern (such as AACG) or even just a single nucle...
more »

2016-12-01 05:12 (3) Answers

C++ Sorting vector of structs alphabetically

I have this record management program I am building for an introductory programming course. Part of the code is the function sortEmail which is supposed to sort the vector recordList alphabetically and calls the sortAlphabet function. I'm getting an ...
more »

2016-11-27 00:11 (1) Answers

Vector element ID's C++

UserFile.open(cname + ".txt"); int numOfElements = name.size(); if (UserFile.is_open()) { name.push_back(cname); pass.push_back(cpass); posx.push_back(0); posy.push_back(0); id.push_back(numOfElements); std::cout << "Y...
more »

2016-11-24 03:11 (1) Answers

store function results in a vector

I have a function here that takes samples, it works however I'm struggling to store the samples taken in a vector so that I may plot them; here is my function below: InvCDF = function(n, sd) { for (i in 1:n) { u=runif(1, min = 0, max = 1) x = sqrt(...
more »

2016-11-21 12:11 (2) Answers