Visual C++ :: How To Do Binary Search On A Vector Of Strings

Sep 25, 2012

I'm trying to do a binary search on a vector of strings and keep getting this error. This is the PhoneEntry header file with the class declaration:

Code:
using namespace std;
#include<string>
#include<iostream>
#include<fstream>
#include<vector>
#include"phoneNumber.h"

[Code] .....

View 5 Replies


ADVERTISEMENT

C++ :: Search A Vector Element With Multiple Strings?

Nov 22, 2013

How could I search a vector element with multiple strings

i.e. vector.at(i) = This is a test

How could I search that to look for the word "test" in that element?

View 7 Replies View Related

Visual C++ :: Merge Sort - Binary Search

Feb 25, 2013

I have created a program that first sorts a series of numbers that are input dynamically then an option is given to either use a sequential search or a Binary search. my sequential search works fine but the merge sort coupled with the binary search has a small bug that I just can't seem to figure how to eliminate. I first used my own merge sort but it was really in efficient so a I took a more efficient example and incorporated it in my program but I cant seem to get rid of this bug I'm dealing with. and it seems to be causing a further problem with the Binary seach.

Code:
#include <iostream>
#include <cmath>
using namespace std;
const int N = 10;

[Code] .....

View 3 Replies View Related

Visual C++ :: Binary Search Tree - Implementing Insert Function

Nov 18, 2013

I am unable to implement the insert function properly,every time i run the program i just get the first value and name,i am not getting other Id's and name.

Code:
"(Header File)"
#include <iostream>
#include <string>
using namespace std;
class node {
public:
int ID;
node (string StudentName, int IDNumber) {

[Code] ....

View 4 Replies View Related

C++ :: Binary Search And Sequential Search Algorithm

Sep 16, 2013

Write a program to find the number of comparisons using the binary search and sequential search algorithms

//main.cpp
#include <cstdlib>
#include <iostream>
#include "orderedArrayListType.h"
using namespace std;
int main() {
cout << "." << endl;

[code]....

View 4 Replies View Related

C++ :: Binary Search Or Linear Search For 3D Array

Oct 7, 2014

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.

#include "stdafx.h"
#include <iostream>
#include <iomanip> //for setprecision
#include <math.h>

[Code].....

View 3 Replies View Related

C :: Function To Search If Two Given Strings Are Equal

Jul 9, 2014

I made my own function to search if two given strings in my function are equal but the problem is if i pass two variable like hello,hello ... result is string equal but if i pass hello , hello also give me string equal because last 4 characters same to last 4 characters of hello ...

Code:
int getSimilarityOfTwoStrings(const char str1[],const char str2[]){
int str1Len = getStringLength(str1);
int str2Len = getStringLength(str2);
int i = 0;
int j = 0;
bool truefalse;

[Code] .....

View 3 Replies View Related

C++ :: Search Array Of Strings - How Many Time Word Was Used

Feb 4, 2013

The function should search the array of strings to find how many times the word 'the' was used. but its only returning a 0.

int FindThe (int The, char Paragraph[], char Pattern[]) {
for (int i(0); i < 500; i++) {
if (Paragraph[i] == Pattern[0] {

[Code] ....

View 5 Replies View Related

C/C++ :: Search In File And Extract Content Between 2 Strings

Jun 8, 2014

I need to develop a simple program, i have 2 variables (begin, end), and i need to search in a file, And extract the string between the Begin and the End variables to a new File, For Example:

my text file: file.txt:

some text here<StartHere>more text here</EndHere>text text

C++ Program:

//Declear 2 variables
strcpy_s(begin, string("<StartHere>").c_str());
strcpy_s(end, string("</EndHere>").c_str());

//And now, search in the Text file, And Extract the text between the begin string and the End string.
<...>

The Result should be: NewFile.txt with the content:

<StartHere>more text here</EndHere>

That's it!, Here is what i have for now:

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main() {
int ocurrences_count = 0;
int ocurrences2_count = 0;
char word[20]; //this array will save user input

[Code] ....

View 1 Replies View Related

C/C++ :: Swapping Vector Int And Vector Strings

Mar 30, 2013

I want to have it so that when i ask for the person witch item they want to drop on the ground it goes into another vector that i can pick back up the item if they want it back and erase when they walk away.

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cmath>  
using namespace std;  
    struct InventoryItem

[Code] ....

View 4 Replies View Related

C++ :: Search Binary Tree

Aug 12, 2014

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

[Code] ......

View 3 Replies View Related

C++ :: Binary Search Tree With Templates?

Oct 27, 2014

I am trying to implement BST using templates. This is the code that i have written.

Code: template <class T>
struct node
{
struct node *left;

[Code].....

There are no errors but the program hangs. What is the mistake with this program ?

View 2 Replies View Related

C :: Binary Search Program Using Graphics

Nov 22, 2013

Looking for the binary search program using c Graphics....

View 5 Replies View Related

C :: Binary Search With String Algorithm

Oct 3, 2013

I'm trying to use the biSearch function to search for a keyword in the dictionary.

Code:
int biSearch(Dict DictEntries[MAXENTRIES],int start, int finish,char *keyword) {
int mid = (start+finish)/2;
int index = strcmp(DictEntries[mid].key,keyword);
printf("%s=%s
",DictEntries[mid].key,keyword);

[Code] ....

View 4 Replies View Related

C++ :: Binary Search Tree Printing

Apr 19, 2014

I am not sure how to use the parameters ostream and enum type in a print function.

enum TraversalOrderType {preorder, inorder, postorder};
template <class ItemType>
void Tree<ItemType>::print(ostream & Outstream, TraversalOrderType order) {

[Code] ....

Is this the correct way to call the print function?

int main() {
Tree<int> tree1;
tree1.print(cout, preorder);
return 0;
}

View 2 Replies View Related

C++ :: Binary Search Tree Remove?

May 10, 2014

I don't know why, but my remove function doesn't seem to operate properly. The rest of my code is fine, so I am trying to pinpoint the exact location of my error. The else if statement remove(root->left, data) should've been called twice, but it only called once.

BST* smallestNode(BST* root)
// precondition: T is not null
// postcondition: return the node in the subtree rooted at T that

[Code]....

View 2 Replies View Related

C++ :: Binary Search Delete Function

Nov 26, 2013

I am having an issue when i try to delete a node with 2 children it either doesn't delete anything, or wigs out in various manners deleting the wrong node or replacing a node with a various memory location. As follows, here is the delete function:

void BST::dele(){
bool found = false;//initialize a bool type to "find" the element to be deleted
if(root == NULL) return;//well if the tree's empty, nothing to be found right?
current = root;//set the current to the root to traverse the tree in search of the element
node* parent;//create a parent node for use once the node has been deleted
while(current != NULL){//traverse the tree

[Code] .....

View 1 Replies View Related

C++ ::  Traversal In Binary Search Tree

Apr 29, 2013

Traversal of binary search tree. In my header file there is a function setTraversal (public) and private print file. As I understood from teacher's explanation, my setTraversal function should call the recursive print function and print the list depending on selected order (pre,in or post-order). I still cannot get my head around what should be in setTraversal function definition. All resources I read last two days explain each order separately (preorder, inorder, postorder). How can I combine them? Here is my code:

#include "NodeTypeBST.h"
#include <iostream>
enum TravType {PRE, IN, POST};
template<class T>
class BST

[Code] ....

View 1 Replies View Related

C++ :: Binary Search Tree Optimization?

Jul 9, 2013

I was working on binary tree implementation and came up with this implementation. optimize this code?

/*
Binary Search Tree(BST)
06/27/2013
*/
#include "iostream"

[Code].....

View 3 Replies View Related

C/C++ :: Binary And Linear Search Program

Mar 30, 2014

// ***This program uses a binary search and a linear search to see if a 3-digit lottery number matches the number on any of the player's tickets.***//

#include <iostream>
using namespace std;

[Code].....

bunch of errors and completely lost. what it's supposed to look like.

View 4 Replies View Related

C/C++ :: Making Binary Search In Array?

Jul 15, 2014

i was trying to make a program that will asks the user for 10 numbers.then asks the user to enter integer search key.next,the program should find the value in element.i used linear search.my code is like this:

#include <iostream.h>
#include <conio.h>
int linearsearch(const int [], int, int);

[Code]...

how should i make a program that will uses binary search instead of linear search?

View 4 Replies View Related

C/C++ :: Implementing A Binary Search Tree?

Mar 20, 2014

I'm working on a programming homework that asks us to implement all the functions of a Binary Search Tree using templated classes. I'm almost done with it but I'm sort of stuck with the last part which is the `search` function. For this part the homework asks for the following requirements

Quote

Node<T>* search(T value, Node<T>* subtree)

if the current node's value is the one we're search for, return a pointer to itif the current node's left and right subtree's are empty (both m_left and m_right are looking at nullptr) then return the nullptr to indicate we didn't find the valueif the value is less than the current node's value, return the search of the left subtreeif the value is greater than or equal to the current node's value, return the search of the right subtreeMake sure to only traverse a subtree if it's not null

View 1 Replies View Related

C/C++ :: Creating A Binary Search Loop?

Oct 13, 2014

I am creating a binary search program that lets the user input up to 10 integers and then the program displays the array and sorts it. When the user is prompted to select an integer, if the integer is in the array, the program responds with the array subscript part. I can get the loop to work once and maximum twice, but then it wont search for the array or say value not found even though the number in in the array. I tried making the values NULL but that only lets me go through it one more time.

Here is my code:

#include <iostream>
using namespace std;
//Functions
void printArray(int);
void selection(int);
int binarySearch(int,int,int);

[code]....

View 6 Replies View Related

C++ :: Lexing File Into Binary Search Tree

May 22, 2013

Standard example. I have a large text file and I wish to lex it into words. I tell the program that all words are delimited by ' ' ';' ':' and ''.

When I run the program it seems to be outputting the occurances of the letters and not the words. Im gobsmacked, I dont know what the hell is going on. Heres the function that lexes letters and not words. I want words dammit words!!

First youll see I define root node and point it to null; This forms the base of the BST. Then keep munching one character at a time until EOF reached. If the character is not a delimiter, assign it to "word" string, character by character. If it is a delimiter, take the so-far-constructed "word" and chuck it in the BST, then clear the word string through .clear().

Repeat until done. But its not working.

Code:

struct masternode* lexical_scanner(ifstream* inputfile) {
string word;
char c;
struct masternode* root = NULL;
while (c!=EOF){

[Code] .....

All the other functions in the source file are just fine, I've tested them in other apps and they are purpose built.

View 6 Replies View Related

C :: Guessing Game Program - Binary Search

Apr 5, 2014

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 );

[Code] ....

View 2 Replies View Related

C :: Binary Search Tree - Struct Data

Oct 24, 2013

I was working with binary search tree and came up with the solution:

Code:
#include<stdio.h>
#include<stdlib.h>
typedef struct data {
int x;
struct data *left;
struct data *right;

[Code] .....

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved