I am trying to implement a Task scheduler where i have n number of tasks. The Idea behind my task scheduler is that in a loop of queues of a vector, task should get enqueued to the shortest queue among the loop of queues, which is done by the following code.
#include <vector> #include <queue> std::vector<std::queue<int> > q int min_index = 0; task t // implemented in the other part of the program
[Code] ....
Next i am trying to extend this paradigm to reduce the overhead time of the scheduler, Instead of searching the shortest queue every time, search after some condition ie. search the shortest queue after 5 tasks gets enqueued to the shortest queue.
i need to do something like this
#include <vector> #include <queue> std::vector<std::queue<int> > q task t // implemented in the other part of the program while(q[min_index].size()!=q[min_index].size()+5) // check whether current min_index queue's size is increased 5 more times if not goto enqueue
inputting a search array. I tried putting a binary search but I can't get it to work. everything else works up until I put the value I am searching for in the array, then it just crashes.
How it suppose to work: input 2 coordinates with a value each then it calculates the distance between them then it suppose to let user search the coordinates for a value and state if found which coordinate it is at.
i am having difficulties doing this program. i dont know how to search for the value 80.
#include <cstdlib> #include <ctime> #include <iostream> using namespace std; class SortArray { public: int randomArray[]; int find(int randomArray[], int len, int seek);
So i create a simple structure,that has a firstname, lastname, age, dateofbirth.I would like it if i type what I am searching for print out there is one or not.But i have some trouble with equals(in array).. i type in the same "keresettnev" as "tanulok[i].Firstname" but it thinks not the same. (it works with age..)
It has been a while since I built a binary tree from scratch so I decided to do it. Everything works fine but this one function. When I enter a number to search it just keeps running and allowing me to keep enter numbers.
Code: void tree::search(int key,Node* leaf) { if (leaf == NULL) { std::cout<<"The tree is empty
You have to implement a data structure to represent graphs,directed or undirected,that tries to avoid the wasted space in the representation of a graph with adjacency matrix and the difficulty of searching the edges with adjacency list representation.We consider that the vertices are numbered from 1 to nverts and the exit degree of each vertex is at most MAXDEG. If deg[i] is the exit degree of the vertex i then the neighbors of the vertex i can be saved at the matrix edge[i][j], 1<=j<=deg[i].
Write a program that reads the datas from a file: if the graph is directed or undirected(1 or 0), the number of vertices (nverts),the number of edges (nedges) and the first and the last vertex of each edge.Write the function dfs that, with argument the data structure that you implemented before for the representation of a graph, prints the edges by the depth-first search of a graph. What I've done so far is: I wrote a program that reads these information from a file, calculates the exit degree of each vertex and creates the matrix edge[i][j]. What data structure do I have to implement???
What is "if(prev)"? Wouldn't "prev" always have the same value? Secondly, if tmp is NULL (which will be the case when the loop if(ptr->val == val) finds a match the first time it is run), is *prev assigned a NULL?
I should state that I am recently new to C programming. I have dabbled with Python in the past, but nothing formal. I am taking a C programming class, but it is an introductory course. As such, the instructor is moving extremely slow through the material.
With this program, I am trying to search a given text file (line-by-line) for user-submitted data. I then want to be able to store which line that data was found on. The program runs, but it always results in "Sorry, couldn't find a match." Even if it shouldn't.
I should probably explain my overall goal with this program.I would like to write a program that will calculate the molecular weight of a compound. I expect the user entered molecular compound to be something like this: CH3COOH (An equivalent entry could be C2H4O2)Also, it needs to be case sensitive because the chemical formulas are case sensitive.
The output will be "The molecular weight of CH3COOH is xxx.xxxxx grams".I have two text files as well. One contains a list of all chemical symbols, and the second is a list of all atomic weights in the same order as the first. I want to place the user inputted data into an array, then search for each element of that array in the chemical symbol text file. It will show which line it was found on, then I can use that line to grab the atomic weight from the second text file.
I am trying to get my program to search for the account ID in the structure and deletes the record as the account ID is found. The problem is that my codes are not working. (since my whole program is too long, I only show a part of it.) Here are my codes:
Output to terminal: 0 2 3 1 4 5 but it should be: 0 2 4 5 3 1
Here's my code:
#include<stdio.h> #include<assert.h> /* maxVertices represents maximum number of vertices that can be present in the graph. */ #define maxVertices 100 void Dfs(int graph[][maxVertices], int *size, int presentVertex,int *visited)
i have a work to do that consists on a given char pointer to a chain and a also given char pointer to a string. i have to search that chain in the string, and return the position where the beginning of the two it's equal. but only if they are equal.
example: string is "abcd" and the chain is "bc". want to find the chain, and if it exists, the position return will be 2. in the work it says that we should use sprintf() too. here is my code, which is incomplet yet.
Code:
char* pos(char* C,char* S){ char *str = S; char *chain = C; int i, j, temp; int lengthStr = strlength(C); int lengthChain = strlength(S); }
[code]....
my doubt is how to use sprintf() and where. if i have to use malloc() and free(),
i am trying to create a c++ program that asks for an input and determines if it is a question or not by searching each word from the input across a database (txtfile)..so far I have managed to make it search the database for the word but it only works on one word.... i would like to be able for it to search every word on the input separatly..here is the code:
I am writing a program that determines how many times a word is repeated in a file without a main function. I almost have it correct but it doesn't exit after it finds how many of the last word and it just loops.
Here is my coding
int count_the_word(string filename, string word) { ifstream word_search; int number_the = 0 int number_is = 0 int number_of_romeos = 0 int number_case = 0 string user_input;
[Code] ....
there is also two more lines from a different txt file i just havn't coded them yet.
the main function that is used to test it is as follows cout << count_the_word("raj.txt", "the") << endl; cout << count_the_word("raj.txt", "is") << endl; cout << count_the_word("raj.txt", "Romeo") << endl; cout << count_the_word("raj.txt", "case") << endl;
it works like its supposed to but like i earlier mentioned it outputs another number after it finds how many "case" are in the file and then it loops asking for a filename.
When the user selected this option, your program should be able to accept a character from the user and search for this character from the phrase. Your program should be able to identify the location of the character in the phrase. I've try the arrays but still can't go .....
I am looking for a way that I could check the information of a folder and a drive, to show the data size and storage amount (KB, MB, GB). This is so that I can compare the size of a folder to the storage capacity of a disk drive.
We are working on building a cluster and needed to create or find a program writen in C that we can run. I was thinking a program that finds prime numbers and insert them into a MySQL database. I have never worked with C so I don't know where to start or anything. I have a week to prove our project is worth keeping and our cluster is almost completely installed we just need to create a program.
I'm trying to get a project for an assignment. I have got it nearly working but the final result is completely erroneous. We are given two text files. One that has a noise image. This needs translating into a binary image. Which is quite easily. Using a threshold I just cycle through a loaded text file with a threshold and it refines the image perfectly. Then it saves fine. Obvious with this being a binary image it saves it as values of 1 and 0. However, the other text file is a shuffled image in set block sizes (512 x512 image into blocks of 32x32) with values of 0 or 255 for each cell.
So I set the cell values of 1 to 255 and 0 remain the same. Here is where I have the problem. My solution has to use a Nearest Neighbour search using Sum of Squared Differences. I have constructed a solution that should work on paper but it gives me a completely erroneous output for the solution to the second image.
My solution is to go by each block X and Y (512/32 = 16 x and 16 Y blocks) of the binary image(allmost perfect normal image) and for each one find the lowest SSD score and set the solution as it. Then goto the next block and repeat. Here is a copy of some of my code.
.H info
class Matrix { int M, N;// No of rows and columns public: Matrix(int sizeR, int sizeC, double* input_data); Matrix();// default constructor for empty type Matrix(int asizeR, int sizeC); double get(int i, int j)const;
[Code]....
It then writes to file. I excluded the binary image as I know that is all correct.
I'm trying to get a project for an assignment. I have got it nearly working but the final result is completely erroneous.
We are given two text files. One that has a noise image. This needs translating into a binary image. Which is quite easily. Using a threshold I just cycle through a loaded text file with a threshold and it refines the image perfectly. Then it saves fine. Obvious with this being a binary image it saves it as values of 1 and 0. However, the other text file is a shuffled image in set block sizes (512 x512 image into blocks of 32x32) with values of 0 or 255 for each cell.
So I set the cell values of 1 to 255 and 0 remain the same. Here is where I have the problem. My solution has to use a Nearest Neighbour search using Sum of Squared Differences. I have constructed a solution that should work on paper but it gives me a completely erroneous output for the solution to the second image.
My solution is to go by each block X and Y (512/32 = 16 x and 16 Y blocks) of the binary image(allmost perfect normal image) and for each one find the lowest SSD score and set the solution as it. Then goto the next block and repeat. Here is a copy of some of my code.
.H info
class Matrix { int M, N;// No of rows and columns public: Matrix(int sizeR, int sizeC, double* input_data); Matrix();// default constructor for empty type Matrix(int asizeR, int sizeC); double get(int i, int j)const; ~Matrix();