#include <iostream> #include <stack> using namespace std; struct valpos//structure which carries information about the position of the cell and its value { int val; int row; int col;
how can a breadth-first-search-tree include every node have ancestor list. every node have multiple ancestor list(because every node may be multiple parents)
I'm new to program breadth first search and for my assignment we have to implement a breadth first search graph and output the order of the traversal. The problem is when I run my program I do not get any output from my traversal. All I get is "Breadth First Search Traversal starts at Vertex 2 and the order is: "
Here is my Queue class
//Declaration of node struct node{ int info; node *next; }; //Defining Queue class class Queue{
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???
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)
What I have done : Created functions to accept inputs from user and read,print out adjacent matrix.
What I need : How do I start DFS in adjacent matrix so that I can output the vertices of each connected component of a graph? I'm confused with adjacent matrix and the term 'component'.
#include <stdio.h> #include <iostream> #define maxV 8 using namespace std; int V,E,x,y; int a[maxV][maxV];
i have come across this code for calculating the depth of a binary tree.
int maxDepth(Node *&temp) { if(temp == NULL) return 0; else { int lchild = maxDepth(temp->left); int rchild = maxDepth(temp->right);
[Code] ....
In these recursive calls i am really clue less about how the statements i numbered from 1 to 4 would be executed...in every recursive call...???
Lets temp has left depth of 3 and right depth of 100 then...in last 97 recursive calls max(temp->left) would be doing...????? how these recursive mechanism work here... I want to know specifically how these left node and right node recursive calls are co-ordinating with each other????
I wrote this code, but now need to apply a limit to the recursive depth. This is the format that I have to use. How would I pass a limit so that it stops after a given number? I'm just confused about where to apply it.
int compute_edit_distance(char *string1, char *string2, int i, int j, int limit) { if (strlen(string1) == i) return strlen(string2) - j; if (strlen(string2) == j) return strlen(string1) - i; if (string1[i] == string2[j]) return compute_edit_distance(string1, string2, i + 1, j + 1, limit);
I am currently working on writing a word search program. However, I am stuck on reading the used input into the 2-D array. The code I've posted below is only dealing with the user input (I'll work on the word search part once I know i am correctly reading in the user input). I know the coding is bad practice with the use of hexadecimal, and getchar() ect. But I am currently using a microblaze microprocessor and this is just the way microblaze can interpret the information. As for the infinite while loops...that can be changed just trying to figure out how.
My question is how could I change my code to correctly read in the user input into the 2-D array?
Code: #include "platform.h"#include "xparameters.h" #include <stdlib.h> #include <stdio.h> #define MAX 20 int main() { char grid[MAX][MAX], word[30]; int i, j, arr[2],num;
I'm playing with a guessing game program as a personal exercise, but I'm missing a vital piece - the binary search-style code.
"Have the program initially guess 50, and have it ask the user whether the guess is high, low, or correct. If, say, the guess is low, have the next guess be halfway between 50 and 100, that is, 75. If that guess is high, let the next guess be halfway between 75 and 50, and so on."
(We're assuming that the user won't cheat.) I need the average, essentially. As in, (50 + 75) / 2 = 63.. but when I use this method of "guess = (high+low)/2, it just keeps giving me 50. I can't remember what operators I should use to increment the program's response based on the user's input. It's literally a binary search, that needs to go where those TODOs are. If low was chosen, it would have to start by being at least 51, to 100, so I'd have to set that, then find the average.
Code: #include <stdio.h> Code: #include <ctype.h> int main(int argc, const char * argv[]) { int low; int high; int guess; int response; int toupper ( int );
I am building a semi-complicated program and the focus of it will be on the search engine. The current plan is for it to search an online database after keywords and receive a list of responses organized by relevance.
I want to minimize the stress on the server by handling as much of the process on the client side as possible so I wonder how best to split up the tasks.
So far my idea is to have the client send the search term to the server who then compare it with its registry. Collecting the 30 or so most relevant hits it sends it back along with additional information from each entry. Requesting additional hits will be decided by sending a simple int value telling which page its filling up.
Simple example:
"Search word" gets processed by the client to account for spelling errors, context etc (based on what I can implement by myself). An Int value gets added (0 for page 1, 1 for page 2 etc...). The request gets sent to the server who can immediately run the search without processing the search word since that was handled in the client. It locates hits and order them by relevance then send out the information batch decided by the Int.
I'm working on this program for homework an here is the problem:
Write a program that keeps track of a speakers bureau. The program should use a structure to store the following data about a speaker.
Name Telephone Number Speaking Topic Fee required
The program should use an array of at least 10 structures.It should let the user enter data into the array, change the contents of any element, and display all the data stored in the array. The program should have a menu-driven user interface.
So I did the program which is below but now it is asking this:
Add a function that allows the user to search for a speaker on a particular topic. It should accept a key word as an argument and then search the array for a structure with that key word in the searching topic field. All structures that match should be displayed. If no structure matches, a message saying so should be displayed.
Now this where I get stuck, I'm having trouble figuring out how to write down the search function in this program. A function that can work and how to get it to match the topics listed by each speaker.
I have code that creates an index file created from a data file of records.
#include <iostream> #include <fstream> #include <map> #include <sstream> #include <string> #include <iomanip> using namespace std; class Record {
[Code]...
I now need to write a second program that allows the user to enter a command on the Linux command line such as
search 12382 prog5.idx
and returns the information for the record with that key. The code I included for the index file is correct and works properly, but how to write the second program.
Here is the index file created by the first program:
I'm writing a binary search tree program and I got it to compile but as soon as I input something it returns a "segmentation fault error" . I suspect the issue with the code is withing my `add` function.
template<typename T> void BinarySearchTree<T>::add(T value) { if (m_root == nullptr) { Node<T>* node = new Node<T>; node->setValue(value); m_root = node;
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
I have been asked to create a program that accesses an inventory file done in excel, look for a alpha-numeric code, which will be inputed by the user, and return to the user informations related to the position of that code, and informations related to the header of the column in which the code resides.
An example of the function I need the program to perform would be:
User inputs: 1429-R1
And the program returns: Marco's 6A, 8/21/2014, 3/7/2014.
Write a program that will search soccer players data to check whether a name supplied by the user is on that list. For doing the search, the user may provide either the player’s full last name or one or more starting letters of the last name. If a matching last name is found, the program will display the player’s full name and date of birth. Otherwise, it will display “Not found”.
Requirements specification:At the start, the program will ask the user to enter information about 10 soccer players constituting soccer player data. Each soccer player data will consist of the following fields:
Last name First name Birth month Birth day Birth year
The user will be asked to enter each soccer player data on a separate line with the field values separated by a space.
Once the data is entered, the program will display a menu of choices as below:
Chose an option:
(1 – input data, 2 – display original data, 3 – sort data , 4 – display sorted data 5 – search by last name 6 – exit the program )
If the user chooses option 1, the program will ask the user for a data and populate the array of structures that will hold the data for each of the soccer players.
If the user chooses option 2, the program will display data in the order provided by the user (original data).
If use chooses option 3, the program will sort data by last name.
If user chooses number 4 the program will display the data sorted by last name.
If the user chooses option 5, the program will ask the user to enter one or more starting letters of the soccer player’s last name. It will then search the soccer player data for the matching last name. If a match is found, it will display the first player found with the matching pattern. If a match is not found, the program will display “Not found”. If the user enters two forward slashes (//) for the last name, it will no longer search for the name. Instead it will display the main option menu.
If the user chooses option 6, the program will display “Thank you for using this program” and will end.
Why my program isint executing correctly. Here is what i've so far . . . .
#include <iostream> #include <string> using namespace std; struct data { string lname; string fname; int birthmonth; int birthday; int birthyear;