Currently I'm implementing a T9 (predective text) project in c++ using n-ary Trees. I've never used the n-ary tree before so I really have some difficulties
I have to add words into the tree, knowing that each node of the tree contains a linked list (for the words) and a vector of pointers to access the next node
the words should be stockes in the different nodes according to their T9 code and then when the user insert a number, my program should display all the words corresponds to that code. For example the code: 4663 matches "good" "home" "gone" ...and so on...
I would like to understand how can I add the words into the Tree and how can I display them later
I want to insert an element into binary tree using pointer passing through functions. In my program i have used three structure which are follows :-
Code:
struct tree{ int data1; struct tree *leftptr; struct tree *rightptr; }; struct list{ struct tree **data; struct list *node;
[Code]...
Here i think problem is in allocating memory to n2 . why i do this because i want to store the address of address of left and right pointers of tree and extract that address to get the address of left and right pointers. Is my method correct ?
Write a program having structure which hold address fields as Name, Address Line 1, City, State, ZIP. Program should able to hold 50 entries of address. Application should have feature/choice option to add, delete and Search address by name .
I'm having a problem filling a vector from a file. Basically, it is adding an empty element at the end. I'm new to Qt and haven't worked with file streams much so how to stop the stream before it adds the extra element.
But, if I add another element to the vector and write that the file look like this.
//file after adding element 132654 0 02132014 132654 0 02132014 0 0 132998 22 02202014
I have it set to append at the moment so that is why the first line is repeated. I figure the problem is with if(in.atEnd()). I could fix it by deleting the last element right after adding it, but that seems like more of a hack than anything else.
I want to add mathematical expression in a binary tree but I have some problems with the algorithm. I found this one:
-If the current token is a '(', add a new node as the left child of the current node, and descend to the left child. -If the current token is in the list ['+','-','/','*'], set the root value of the current node to the operator represented by the current token. Add a new node as the right child of the current node and descend to the right child. -If the current token is a number, set the root value of the current node to the number and return to the parent. -If the current token is a ')', go to the parent of the current node.
Here is the code that I made so far:
template<class T> void Tree<T>::Expr(Node<T> *node, char expr[], int &i) { i++; T x = expr[i]; if(x == '(') { node = node->Left;
[Code] ....
I know that it is a big mess and it doesn't follow the algorithm but this is the problem. For example if the token is '(' I go to the left child of the current node. Then lets say that the next token in the expression is a number. I add this number to the current node and I must go back. But how can I go back to the parent? I will go back to line 13 and the program will end. What should be the structure that I must use?
// Write a function called insertEntry() to insert a new entry into a linked list.
Have the procedure take as arguments a pointer to the list entry to be inserted (of type struct entry as defined in this chapter), and a pointer to an element in the list after which the new entry is to be inserted.
// The function dveloped in exercise 2 only inserts an element after an existing element in the list, thereby prenting you from inserting a new entry at the front of the list.
(Hint: Think about setting up a special structure to point to the beginning of the list.)
This is a working version of the exercise, but I don't think I'm doing what's asked. I was able to add an element to the beginning of the list using an if statement, not creating a special structure that points to the beginning of the list. How would I go about creating a special structure that points to the beginning of the list to add a new element at the beginning of the list?
So I have linked list and function which deletes element if next element is bigger, so my code is working but its not working with first element, in the comment I have wrote code which I would code for checking that first element, but when ever I check it is blowing up all program.
#include <iostream> using namespace std; struct llist { int x; llist *next;
I have a global list that contains smaller lists of char arrays. I have an issue where when I'm reading back the inner lists the last element of one list seems to point to first element of the next.
So my data looks like the below (values separated by commas with the pairs separated by tabs. The last pair in a line is the same as the first). When I read the first list back instead of seeing "456.678,678.98" as the last element in the list. I see "435.67,234.98" twice: at the end of the first list and start of the other. I have debugged when the list is populated and can see the correct values going in so I can't figure what's happening.
obstacle_list = op_prg_list_create(); while (fgets(line, sizeof(line), obstaclePositions_traj_file) ) { token = strtok(line, " "); //Pull the string apart into tokens using the
I have an std list of type double.. and the list is always guaranteed to have just 2 elements. I need to get the value of element 2 minus element 1. What is the least amount of code to accomplish that?
I tried this:
Code: list<double> dList; dList.push_back(1.0); dList.push_back(2.0); list<double>::iterator iter = dList.begin(); list<double>::iterator iter2 = dList.end(); double result = *iter2 - *iter;
For my data-structures class, I am attempting to create a binary search tree template to be used to create an AVL tree. I've written a Generic_Tree template for the BST to inherit from, and before I jump into implementing the AVL tree I'm testing the BST member functions. Everything was compiling fine until I added the BST insert() function. Now, I'm getting the following error message from my linker:
undefined reference to 'BST<void>::insert(int, void*)'
I'm making my first steps in STL, and I have a few question:
Is there a way to get an iterator to the i'th element in the collection (set or list), instead of just to the end or the begin?
And another question: Let's say I have an iterator, pointing to some element in my collection, and I use erase() (which takes as parameter an iterator that points to the soon-to-be erased element), what happens to that iterator? will it now point to NULL?
My code has been acting odd. I made a function that layers my art resources but only the last tile of my art resource acts the way it should. My character goes behind and in front of the last tile and gets printed correctly. Strangely its really exclusive to the last tiles I print. What I need is to figure out in step by step order what going on with my code sample below and be able to layer the resources.
Here is a small sample of my main function. This is how I do my rendering.
Code: Int main (int arc, char* args[]) { //Move class Move character; //Class Tile & Side Tile Tile *tiles [TOTAL_TILES];
how to delete an element(s) from an array; suppose I have an array x[10] = {1,2,3,4,5,6,7,8,9,10}, and I want to delete array{5} so that the values of the array become {1,2,3,4,5,7,8,9,10}; how do I go about this? This is not the same as setting the value of array{5} to null; but completely eliminating it so that it does not get printed alongside the other elements of the screen.
How can I remove an element in a list when I have only an iterator that points to the object I want to remove. Is there a build in command? remove() takes an object reference as its argument. Is it possible to convert the iterator into a pointer type so it can be deferenced and passed to remove?
This is the code I am working on:
//player.cpp void Player::CheckCollectableCollisions(std::list<Collectable>& c) { std::list<Collectable>::iterator i = c.begin(); while(i != c.end()) { if (Collider::CheckCollision(pNodes_.front().getLocation(), i->getLocation()))
How would I go about having a pointer to an array element specificity a character in a c-string.Every thing I try will not even build.An array is already a pointer to the first location of the array right?
char *pHead; char *pTail; pHead = sentence[0]; <=== This wont build pHead = &sentence[0]; pHead = sentence[0]*; *pHead = sentence[0]; <===== this builds but is not storing anything
"Write a program in C that finds the element of an array which all the previous are smaller and all the next are bigger than that.If there are more than one print the biggest. If there isn't any print "ERROR" .
EXAMPLE
If the array has 10 elements like this : {2,3,4,6,5,7,8,10,9,8}
The correct answer is 7 , because 2,3,4,6,5 are smaller than 7 and 8,10,9,8 are bigger than 7.
I am working on it for 2 weeks and I can't find a working solution />/>/>
There is the first try :
#include <stdio.h> #include <stdbool.h> int s_data[10]={2,3,4,6,5,7,8,10,9,8}; int main() { int result,i,j,s_len ,tmp1,tmp; bool GT_PREV,ST_NEXT;
How can i form a counter of say 30 elements so that to meet following requirement,
I need to access 5 elements out of 30 elements and out of these 5 elements once the one value is printed (i.e now access for remaining 4 element will be left) other one should get added immediately to this 5 element set, from remaining total 25 elements. In this way 5 element count will be there always.
I am trying this as follows, by forming vector of 30 elements accessing its 5 elements as :
This displays 5 elements at a time but counter "count" waits for to finish off its remaining 4 elements however i want to maintain this counter to 5 elements always.