Example #1
0
//Builds files in correct order. Returns -1 if any point fails. Returns 1 if 
//successful.
int run(){
	list_item* copy = first;

	list_item* save = copy;
	int r;	
	while(hasZero(copy))
	{
		int i = 0;
		Node** nodes_to_execute = malloc(sizeof(Node) * MAX_DEPENDS);
		while(copy != NULL)
		{
			Node nd = *((Node *)copy->item);
			if(nd.numTargetDep == 0){
				((Node*)copy->item)->numTargetDep = -10; //has zero, is not clean
				//nodes_to_execute[i] = &nd;
				nodes_to_execute[i] = ((Node*)copy->item);
				i++;
			}
			copy = copy->next;
		}  
		r = forkExec(nodes_to_execute,i);
		free(nodes_to_execute);
		copy = save;
	}
	return r;
}
    void setZeroes(vector<vector<int> > &matrix) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        
		if (matrix.size() == 0)
			return;

		int rows = matrix.size();
		int cols = matrix[0].size();

		bool curLine = false;
		bool nextLine = hasZero(matrix, 0);

		for (int i=0; i<rows-1; i++) {
			curLine = nextLine;
			nextLine = hasZero(matrix, i+1);
			for (int j=0; j<cols; j++) {
				if (matrix[i][j] == 0)
					matrix[i+1][j] = 0;
				else {
					if (curLine)
						matrix[i][j] = 0;
				}
			}
		}

		curLine = nextLine;
		for (int j=0; j<cols; j++) {
			if (matrix[rows-1][j] == 0) {
				for (int i=0; i<rows; i++)
					matrix[i][j] = 0;
			} else {
				if (curLine)
					matrix[rows-1][j] = 0;
			}
		}
    }