C++ :: Empty State Of Queue?
Feb 18, 2013what is the empty state of queue?
View 5 Replieswhat is the empty state of queue?
View 5 RepliesSo I was wondering if I were to empty the elements of a stack into a queue, but i only wanted to empty the even numbers or the odd ones. What would the if statement be to accomplish this. Im guessing for even it would be something like if(number % 2!=0)? What about for odd?
View 2 Replies View RelatedUse your language’s native queue class to write the following program: create a class, Patient. The class has 2 members: name of type string; wait_time, a non-negative integer. Read definitions of patients from a file and add the patients to a queue. Write a loop that dequeues a patient from the queue and then decrement the patient’s wait_time. If the patient’s wait time is greater than 0, then the program enqueues the patient again. Otherwise it discards the patient. The loop continues until the queue is empty.
Header File
Code:
#include <string>
class Patient {
public:
Patient();
std::string name;
int wait_time;
bool empty() const;
[Code] ....
I have a paradigm in a loop of queues of a vector,if a condition is true,increase sizes of the queue of that particular queue in the loop of queues, if condition is false, the queuesize is left as such in loop of queues. After this operation i need to search the queue sizes of all queues and enqueue in the shortest queue.
I want to do something like the code given below
#include <vector>
#include <queue>
int min_index = 0;
std::vector<std::queue<int> > q
std::size_t size = q.size();
[Code] ....
How to implement this logic?
will q[i].size=q[i].size+5 increase the queuesize by 5 for the ith queue?
I want to create command line game in Linux but I don't know to get the key state. I heard of getch() but that stops the program.
View 1 Replies View RelatedI thought that an operator performs a permanent change in a local variable. For example, if x is 00000000 00000000 00000000 00000011 (a 32 bit unsigned integer that resolves to value of 3) and p is 2, in the expression "return (x >> p) | (x << (s - p))", the right shift would permanently change x to 0 and the time we evaluate x again in "(x << (s - p))", x will already be 0. If that's the case, then this function doesn't make sense. This function makes it seem like that the >> and << operators do not change the value of x. It makes it seem like first we right shift x to 0 and then left shift by 20 bits to make x 11000000 00000000 00000000 00000000. If that's the case, then the function does exactly what it is supposed to do (rotate the bits). So which is it?
unsigned int rightrot(unsigned int x, unsigned int n) {
size_t s = sizeof(x) * CHAR_BIT;
size_t p;
if(n < s)
p = n;
[Code] ....
The purpose of the code is to read in state names, say california and print CA. However, if it was a state with two words, it would read in only the first letter of each. I.E New Hampshire would be NH.
here's my code:
#include <iostream>
#include <iomanip>
#include <cctype>
[Code].....
I am able to get the one word states and tried getting the two word states but it doesnt work.
I am making a finite state machine for a lab. I have here a 2 files with the code for the FSM. I know it isn't finished yet, I know what needs to be put in. The only things I would need help on are the errors that I get.
Warrior.h
#ifndef _WARRIOR_
#define _WARRIOR_
#include "State.h"
[Code]....
I am supposed to take the three string lines from a text file and then individually reverse them and state whether or not they are a palindrome. I have the three lines from the text file into string variables already but I am not sure on how to reverse them and then see if they are the same reversed(palindrome)
Here is my code so far -->
#include <iostream>
#include <string>
#include <cctype>
[Code].....
EDIT: Ignore line 123 and down in the code. That was merely test code and will not be used.
Question: State the values of each of these int variables after the calculation is performed. Assumed that, when each statement begins executing, all variables have the integer value 5.
a) product *= x++;
b) quotient /= ++x;
What is the answer for a and b?
When running my code in Visual Studio, there is a particular point in the code where my program is crashing. To debug this, I am adding a break point in Debug mode just before that point, and observing what happens as I step through the code. However, to get to this break point in the code takes about a minute of running the program. So I'm wondering if there is a tool in Visual Studio to reload the state of a program's memory from a previous run, so that I can immediately get to the break point without having to wait for a minute each time?
View 6 Replies View RelatedI am trying to initialize this chunk of code without it starting at the main menu in my state program:
boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
tcp::resolver::query query(argv[1], argv[2]);
tcp::resolver::iterator iterator = resolver.resolve(query);
chat_client c(io_service, iterator);
boost::thread t(boost::bind(&boost::asio::io_service::run, &io_service));
char line[chat_message::max_body_length + 1];
This code came from a example at the boost example list: URL.....I want the networking to start when the multiplayer state initializes. This is how my program basically looks like:
//Main.cpp
main() {
if (!quit) {
while( handleing_events ) {
CurrentState->handleEvents();
[code].....
I tried to put the stuff in extern at states.h, and initialize it at Multiplayer(), but in handleEvents & ~Multiplayer, it says "c" is not defined...
In the following code example of the State Design Pattern, in the main code at the bottom it defines an instance of class Machine, and then calls Machine::off;. Why doesn't it instead call fsm.off;?
Machine fsm;
Machine::off;
Then I tried imitating that by adding a class Abba, and then doing:
Abba a;
Abba::DoStuff();
but that didn't work. Why?
Full code example:
// StatePattern.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Machine {
class State *current;
[Code] ....
I'm supposed to create a circular buffer that reads an input file and outputs data after running though basically an integral equation. Everything my be referenced by pointers. When I build I am being told segmentation fault: 11. From what I have gathered that means there is a problem with my memory allocation correct? I'm including the custom header file and the main.c as well.
header file :
#ifndef FSM_H
#defineFSM_H
#define INPUT_BUFFER_LENGTH 2
#define OUTPUT_BUFFER_LENGTH 2
#define INITIAL_INPUT {0,0}
#define INITIAL_OUTPUT {0,0}
[Code] .....
I have written my code, but can't seem to figure out why it doesn't enter the while loop and start asking for Input.
Code:
#include <iostream>
#include <string>
using namespace std;
int main(){
//declare variables
string cityName = "";
string stateName = "";
[Code] ....
I am a beginner trying to write a program that would state a user's chinese zodiac and horoscope sign after inputing his or her birthday. I have been, however, having trouble getting the program to run correctly.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define CAPRICORN "G"
#define AQUARIUS "W"
#define PISCES "F"
[Code] ......
A file is created but its empty. And when I first create an entry and then display all the entries, it does nothing.
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
using namespace std;
class comp {
[Code] ....
We have been assigned to create an iTunes library. Everything compiles in my other .h file but my main is not happy with my object declaration. It keeps stating "primary expression before '{'". Here is my main code:
#include<iostream>
#include<string>
#include<fstream>
#include"myTunes.h"
using namespace std;
//function protocols
void read(string);
[Code] ......
This code:
#include <iostream>
class Foo {
};
int main() {
Foo foo;
std::cout << sizeof ( foo ) << std::endl;
std::cin.get();
return ( 0 );
}
produces this result: 1
Why is the size of an instance of Foo 1, although it doesn't have any member variables?
It has been a few years since I have had to do this, but I need to declare a method in my base class, but produce no code for it. Then when this library is used by my second project I will derive a class from this base class and put the code into it there. How is this possible? I used to know how but do not remember how now.
The library is a static library designed for linking with both 32bit and 64bit Windows applications to handle a lot of the tedious stuff with Windows programming. The method in question handles specific command inputs. However, since each program that uses this library will have different uses for these commands, I want to leave it up to the user to code their own handling, but require it to be coded in the derived class.
So this is my working code with sql i want convert it so i can read it from xml, basiccl i need to fill empty list with xml column BrivDat..
var connStr = @"Data Source=(LocalDB)v11.0;" +
@"AttachDbFilename=C:dbaseAdaPlus.mdf;Integrated Security=True";
List<DateTime> Holidays = new List<DateTime>();
using (SqlConnection conn = new SqlConnection(connStr))
using (SqlCommand cmdd = new SqlCommand("select * from Brivdienas", conn))
[Code] ......
I have a doubt related Size of empty structure. I know the answer of empty structure is "0".
How and why the Result got ZERO..??
I am writing a c++ program in Linux.. I am reading a line from commandline at run time using "getline(std::cin,str);". now, what i want is if i left the commandline as idle (terminal as idle), then i want to know that the commandline is empty... is it possible ???
View 4 Replies View RelatedI've been trying to figure out how to implement a way to save this board state throughout a user's inputted path. At the end, I need the output to print out the board states (user's path) of how he or she got the puzzle solved. This puzzle is the 15 Puzzle; but we have it to change by the user's input on what size they want to play (3x3 to 5x5). How to save the board state of each user input, then print those out in order from beginning to solved puzzle state. Subsequently, I would also need transferring the board state to change with using a vector to store the size based on user input. How to proceed, using a first search to solve the puzzle from the current board's state.
calculations.h
Code:
/*Calculations set as a header to keep compiling simple and faster*/
#ifndef calculations
#define calculations
int solved[5][5];
void initialize(int board[][5], int);
void slide(int board[][5],int move,int);
bool isBoardSolved(int board[][5],int);
[Code] .....
I wrote a template function which use dynamic array as parameter. But if parameter is a empty array, it have compile error.
code:
#include <iostream>
int arry[] = {1,2,3};
int empty_arry[] = {};
[Code]....
compile error:
[zengchao@cmcc-server2 ]$g++ test.cpp
test.cpp: In function ‘int main(int, char**)’:
test.cpp:16: error: no matching function for call to ‘array_parameter(int [0])’
I started making something for my class and the thing im getting stuck with is this function:
void ucitajOdgovore(string asocijacija[21]){
int brojac=0;
ifstream fajl;
string putanja;
/*srand(time(NULL)); int random=(rand() %5) +1;
switch(random){
[Code] ....
In the main, i pass real string array "asocijacije" in function which i use in it, and when i use it after this fun. i get an empty array. Its like it didnt happend and i cant see where i went wrong.