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


ADVERTISEMENT

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/C++ :: Linear Search Not Found Output

Jul 3, 2014

How to return a message saying that the value searched for is not found. We had to pull the data in from a .dat, i won't let me attach it as a .dat so I attached it as .txt. I know my it's sloppy. I usually clean up what I can once it is working properly.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int ccnt;
int size = 10;

[Code] ....

Attached File(s) : dat45.txt (273bytes)

View 3 Replies View Related

C :: Linear Search Function Accessing String In A Struct?

Apr 5, 2013

I currently have a file which allows inputs to record different transistor types. I then have the task of accessing this structure, find a certain manufacturer ID, and print the information about this particular transistor.

My problem is accessing the array to search through.

Here is my code:

Code:
#include "stdio.h"
const int IDLEN=30; //All constant values defined
const int POLARITYLEN=3;
const int MAXSTOCKITEMS=10;
//First structure defined
struct TransistorRec {

[Code]......

The errors I am currently getting are on line 54 'expected primary-expression before "struct"' and on line 60 ' 'maunfacturersID' undeclared'

View 11 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 :: 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 :: Linear Search Script - Calling Array Inside Of User Defined Function?

Jul 24, 2013

im tasked with creating a linear search script using functions on a 10 element array. the elements are to be supplied by the user as is the search target.

I understand how to create the array and gather that information from the user as well as howto set a variable for "target", this is what im calling it. Those two parts are simple enough.

I am not fully understanding the calling of an array in a function as a pointer. i semi understand the use of a pointer and howto call a normal pointer in a function. i also understand that an array is nothing more then a "special" pointer with a set of consecutive address blocks for the size of the array.

My first user defined function is simple enough

Code:
ReadArray(int A[], int size){
int i;
printf("Please enter %d integer numbers separated by spaces:
", size);
for (i = 0; i < size; i++)
scanf("%d", &A[i]);
}

Sso nothing out of the ordinary there. that should be a standard for loop and use of scanf, sadly prof has not covered ssanf or any of the other options so i am stuck using scanf for now. maybe someday down the line in a other program or after this course ill get the chance to learn about better options for gathering data from the user.

I am confused as to my next function:

Code:
void SearchArray(int A[], int target, int size);

I've not written any code here yet as im not sure if i should call the A[], or *A for the first type of the function?

If i call *A do i then use something like this for my search:

Code:
for (*A = 0; *A < size; *A++)
if (*A < target) or use A[] insteadA?

Code:
for (i = 0; i < size; i++)
if (A[i] = target)

View 6 Replies View Related

C++ :: Linear And Binary Summation?

Feb 6, 2015

I am trying to write a program that will output the contents of an array A into a sum hence title.

Here is my code so far...

#include <iostream>
using namespace std;
int LinearSum(int A[], int);

[Code]....

View 1 Replies View Related

C/C++ :: Binary Search Tree Program - Segmentation Fault Error

Mar 21, 2014

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;

[Code] ....

View 6 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

Visual C++ :: Linear Program For Matrices - System Cannot Find Path Specified

Dec 8, 2012

I have two pieces of code:

Code:
#include <cmath>;
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <iomanip>

[Code] ....

I am using the gnu glpk library to calculate a linear program for my matrices. Why I get the error message exit code 3 which apparently means "The system cannot find the path specified"?

View 12 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 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++ :: 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 :: 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

C :: Search And Delete Function For Binary Trees

Apr 1, 2014

I had an assignment that I completed and it was just inserting values into a binary tree and then displaying it. I was wondering what the code would be if I wanted to delete a number in the binary tree, or if I wanted to search for a number. Here is my code for my assignment.

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

[Code] ....

View 1 Replies View Related

C :: Binary Search Tree In Linked List

Feb 25, 2014

Code:

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
struct bst {
int val, level;
struct bst *left, *right, *parent;

[Code]....

The code above is supposed to be a binary search tree. The main outcome for this program is to display the tree in C each time the user inserts or deletes a value.

Since I am a newbie in C programming, I first tried creating a code that would simply display the values in the tree after a user inserts and deletes, before I proceed to displaying the exact tree.

But when I run it the following output shows:

And when I try to insert another value, It won't display anything and won't respond to any keys pressed.

View 5 Replies View Related







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