c ++ – infinite loop during printing

I try to print the names of the queue when I choose the fifth choice, but I continue to have an infinite loop.

I thought it had something to do with my while loop in the print function, but when I commented on it and hit 5, it keeps printing names for some reason (endless) .

The purpose of the program is however to read a giant txt file containing names and put them in queue. The number of names queued depends on the size of the array in which the user specifies the number of names that he wants to include.
On your mind

#ifndef _QueueClass_
#define _QueueClass_

#understand 
#understand 

Qqueue class
{
public:
// constructor
Qqueue (int cap);
// copy the constructor
Qqueue (const Qqueue & s);
~ Qqueue (); // destructor

// assignment operator
operator void = (const Qqueue & s);
// The member function queues: Precondition: the queue is not full. If the queue is full, this function reports an error.
// add value to the end of the queue
void enqueue (const std :: string & s);


// The queue member function: Precondition: the queue is not empty. If the queue is empty, this function reports an error.
// Deletes and returns the first item in the queue.
std :: string dequeue ();

// The member function front: Precondition: the queue is not empty.
std :: string & getfront () const;

// The member function back: Precondition: the queue is not empty.
std :: string & getback () const;

bool IsEmpty () const;
bool IsFull () const;
// print all items in the queue
void print () const;
int size () const;
int getCapacity () const;

// Get the location of DynamicQueue at a specific index
std :: string & getQueue (int);

// Returns true if both queues contain exactly the same element values ​​in the same order. Behavior identical to the operator ==.
bool is equal to (const Qqueue & q) const;
// Usage: if (q.equals (q2)) ...

private:
int capacity; // Capacity is the maximum number of items that a queue can hold.
std :: string * DynamicQueue;
int num; // How many items are stored in the queue
int front;
int return;
};



#end if
#pragma once

Main program

//

#understand 
#understand 
#understand 

#include "Qqueue.h" // documenton is in the header file

Qqueue :: Qqueue (int CAP)
{
DynamicQueue = new std :: string[CAP];
Capacity = CAP;
before = 0;
return = -1;
num = 0;
}

Qqueue :: ~ Qqueue ()
{
wipe off[]DynamicQueue;
}

Qqueue :: Qqueue (const Qqueue & s)
{
Capacity = to capacity;
front = s.front;
back = at the back;
num = s.num;
DynamicQueue = new std :: string[Capacity];
for (int i = 0; i <capability; i ++)
{
DynamicQueue[i] = s.DynamicQueue[i];
}
}

void Qqueue :: operator = (const Qqueue & s)
{
Capacity = to capacity;
front = s.front;
back = at the back;
num = s.num;
wipe off[] DynamicQueue;
DynamicQueue = new std :: string[Capacity];
for (int i = 0; i <capability; i ++)
{
DynamicQueue[i] = s.DynamicQueue[i];
}
}

void Qqueue :: enqueue (const std :: string & s)
{

// check the queue overrun
if (IsFull ())
{
std :: cout << <<! Error! The queue is full.  n ";
exit (EXIT_FAILURE);
}

if (IsEmpty ())
{
before = 0;
return = -1;
num = 0;
}

std :: cout << "Insertion" << s << "n";

    back++;
    DynamicQueue[back] = s;
    num++;

    if (num > 5)
{
for (int i = return; i> = return - 4; i--)
{
std :: cout << << Name: "<< DynamicQueue[i] << " n";
}
}
}

std :: string Qqueue :: dequeue ()
{
if (IsEmpty ())
{
std :: cout << "! Error! The queue is empty.";
exit (EXIT_FAILURE);
}

int number;

std :: cout << << Enter a number: "<< "n";
    std::cin >> number;

if (num> number)
{
for (int i = 0; i <number; i ++)
{

std :: cout << "Delete" << DynamicQueue[front] << " n";
before ++;
num--;
}
}
other
{
before = 0;
return = -1;
num = 0;
}

std :: cout << "Delete" << DynamicQueue[front] << " n";
before ++;
num--;
returns DynamicQueue[front - 1];

}
std :: string & Qqueue :: getfront () const
{
returns DynamicQueue[front];
}
std :: string & Qqueue :: getback () const
{
returns DynamicQueue[back];
}
int Qqueue :: size () const
{
return num;
}
int Qqueue :: getCapacity () const
{
return capacity;
}
bool Qqueue :: IsEmpty () const
{
return (size () == 0);
}

bool Qqueue :: IsFull () const
{
return (size () == Capacity);
}

Qqueue :: equals (const Qqueue & q) const
{
// Returns true if both queues contain the same items in the same order.
if (size ()! = q.size ())
{
returns false;
}

for (int i = 0; i <num; i ++)
{
if (DynamicQueue[i] ! = q.DynamicQueue[i] )
{
returns false;
}
}

return true;
}
std :: string & Qqueue :: getQueue (int l)
{
returns DynamicQueue[l];
}
void Qqueue :: print () const
{
// int count = 0;

// while (count <num)
// {
// int count = before;
// while (count <num)
// {
// std :: cout << DynamicQueue[i] << " n";
// account ++;
//}
//}
}
int main ()
{
std :: ifstream file_;
std :: string lastname;

file_.open ("all.last.txt"); // open the file in red

if (file_.fail ())
{
std :: cout << <<  nOpen the opening of the file ";
returns 1;
}

int userCap;
std :: cout << <<  nType the number of names you want to put in the queue. ";
std :: cost << "n The max capacity is 500 and the input must be atleast >= 100 "<< std::endl;
    std::cin >> userCap;

Qqueue q (userCap);

for (int i = 0; i < userCap; i++)//enqueues each line specified to the capacity inputted
    {
        std::string temp;
        file_ >> temp;
q.enqueue (temp);
}

file_.close ();

int choice;
std :: cout << <<  nChoice:  n1) Enqueue  n2) Wait  n3) Before  n4) Equally  n5) Print  n6) Save  n7) Exit "; // user input menu
while (1)
{
std :: cost << "nEnter your choice...n";
        std::cin >> choice
if (choice == 1)
{
std :: cost << "nEnter the name to be enqueued...";
            std::cin >> last name;
q.enqueue (name);
}
if not (choice == 2)
{
int number;

std :: cout << << Enter a number: "<< "n";
            std::cin >> number;

if (number <q.size ())
{
for (int i = 0; i <number; i ++)
{

std :: cout << "Delete" << q.dequeue () << " n";
}
}
other
{
while (q.IsEmpty () == false)
{
q.dequeue ();
}
}
}
if not (choice == 3)
{
// display the last name in front of the queue
std :: cout << "In front of the queue:" << q.getfront () << " n";
}
if not (choice == 4)
{
Qqueue q1 = q, q2 (userCap);
q2 = q;

if (q1.equals (q))
{
std :: cout << The copy constructor works as expected  n ";
}

if (q2.equals (q))
{
std :: cout << "Assignment Operator working as expected  n";
}
}
if not (choice == 5)
{
std :: cout << "Queue to print ...  n";
q.print ();
}
if not (choice == 6)
{
std :: cout << "save queue to file on disk ...  n";
std :: ofstream file_new;
file_new.open ("new.last.txt");
int account = 0;
while (count <q.size ())
{
file_new << q.getQueue (count) << " n";

count ++;
}
file_new.close ();
}
if not (choice == 7)
{
std :: cout << "Queue cleared.";
Pause;
}
}

// std :: cincinignner (std :: numeric_limits:: max (), & # 39;  n & # 39;); // <--- Requires a header file .
std :: cout << <<  n  n Press Enter to exit: ";
std :: cin.get ();
returns 0;
} `` `

javascript – Thoughts on using loop-less loop while looping with a try / catch?

I would not do that. This breaks too far from any typical convention for a very small profit.

I am personally against the omission of braces; except in very narrow circumstances. I've seen many questions about stack overflow, as some people omitted the braces and could not understand why "only some lines are running."

It also seems like a new language build and feels a little bumpy at first. It takes an extra second to understand what's going on.

Given the length of the lines, indentation should not be a problem; and even if it is, there are other ways to solve this problem. I would write this in a classic way

async function. doAjax () {
const data = {/ * stuff * /}
const retryLimit = 2;
let retryCount = 0;
let found = false;

while (! found && retryCount <= retryLimit) {
try {
let serverResponse = wait $ .get ("url", data);
// do stuff

} catch (err) {
retryCount ++;
}
}

// do more things
}

If you enjoy playing code reading in an interesting way and try to create language constructs, I recommend trying to play with a language with Clojure (or another lisp). Doing experimental things with the syntax is a little more expected in a language like this one.

Free – Looking for Admin for & # 39; Admin Loop & # 39; | Promotion Forum

I'm sure you're aware of my current project, Admin Loop. I have to focus on the blogging side and the realization of several sections. It would be great to be able to use an administrator to manage the forum while I finish it.

The basic tasks would obviously be to moderate content, post on the forum and keep an eye on it. Looking for a person who can type correctly (no spelling, grammar mistakes, etc.)

I can not offer anything at the moment unless you are interested in advertising space somewhere on the site.

PM or post below if interested :)

functions – improving loop speed with IntegerQ conditions

This is a partial answer only.

Basically, you need a quick way to check if an integer is a perfect square. Here is a moderately fast version, to optimize:

squareQ[n_] : = MemberQ[{0, 1, 4, 9}, Mod[n, 16]]&& IntegerQ[Sqrt[n]]

The triangle is simplified for the two specific cases:

triangleA[a_, b_, c_] = Sqrt[(a + b + c)/2 ((a + b + c)/2 - c)];
t1[n_] = triangleA[n, n, n + 1]^ 2 // FullSimplify;
t2[n_] = triangleA[n, n, n - 1]^ 2 // FullSimplify;

The search is now about 3 times faster:

PerimetreTot = 0;
Make[If[squareQ[t1[n]], perimeterTot + = 3 n + 1];
Yes[squareQ[t2[n]], perimeterTot + = 3 n - 1], {n, 2, 10 ^ 5}]

To improve this, look at the super-fast implementations of squareQ, inspired for example by this question and this Java thread. Probably that compiling, or even handwriting a C subroutine, would be useful.

Partners of the administrative loop | Promotion Forum

I would love to collaborate with other blogs and forums. We would look for sites with similar niches. This would also involve a simple footer link exchange.

Link of the loop of administration – https://adminloop.com

Thank you for posting here before adding just to confirm that we can partner ;)

postgresql – plpgsql: Incompatible parentheses at or near ";" in nested loop structure

I wrote a Do block to keep only the tables in a Postgres database, but I got this error message when I ran the script. I do not see where parentheses are incompatible. I've added the tags after seeing this error message for the first time, but that has not solved the error.

psql $ DBNAME << EOF
DO  $$
TO DECLARE
myschema RECORD;
myview RECORD;
myfunc RECORD;
myseq RECORD;
TO START

FOR myschema IN (SELECT schema_name FROM information_schema.schemata;)
<>
LOOP

- Delete all views
FOR myview IN (SELECT the name of the FROM view pg_catalog.pg_views WHERE schemaname = myschema.schema_name;)
<>
LOOP
EXECUTE & DROP VIEW & # 39; || quote_ident (mychema.myview.viewname) || & # 39 ;; & # 39 ;;
END OF LOOP for each view;

- Drop all functions
FOR myfunc IN (SELECT name_routine FROM information_schema.routines WHERE type_routine = & # 39; FUNCTION & # 39; AND Specific_schema = & # 39; public & # 39 ;;)
<>
LOOP
EXECUTE & DROP FUNCTION & # 39; || quote_ident (mychema.myfunc.routine_name) || & # 39 ;; & # 39 ;;
END OF LOOP for each function;

- Drop all the sequences
FOR myseq IN (SELECT sequence_name FROM information_schema.sequences;)
<>
LOOP
EXECUTE & DROP SEQUENCE & # 39; || quote_ident (mychema.myseq.sequence_name) || & # 39 ;; & # 39 ;;
END OF LOOP for each sentence;

END OF LOOP for each scheme;

END;
 $$ LANGUAGE plpgsql;
EOF
ERROR: Incompatible parentheses at or near ";"
LINE 9: ... my IN (SELECT schema_name FROM information_schema.schemata;)

Final working code:

psql $ DBNAME << EOF
DO  $$
TO DECLARE
myschema RECORD;
myview RECORD;
myfunc RECORD;
myseq RECORD;
TO START

FOR myschema IN (SELECT schema_name FROM information_schema.schemata WHERE schema_name NO LIKE _ pg _% AND # schema_name <> schema_information)
LOOP

- Delete all views
FOR myview IN (SELECT the name of the FROM view pg_catalog.pg_views WHERE path_name = schema_name.schema)
LOOP
EXECUTE & DROP VIEW & # 39; || quote_ident (myschema.schema_name) || & # 39;. & # 39; || quote_ident (myview.viewname) || & # 39 ;; & # 39 ;;
END OF LOOP;

- Drop all functions
FOR myfunc IN (SELECT ram_name FROM information_schema.routines WHERE type_routine = & # 39; FUNCTION & # 39; AND Specific_schema = & # 39; public & # 39;)
LOOP
EXECUTE & DROP VIEW & # 39; || quote_ident (myschema.schema_name) || & # 39;. & # 39; || quote_ident (myfunc.routine_name) || & # 39 ;; & # 39 ;;
END OF LOOP;

- Drop all the sequences
FOR myseq IN (SELECT sequence_name FROM information_schema.sequences)
LOOP
EXECUTE & DROP VIEW & # 39; || quote_ident (myschema.schema_name) || & # 39;. & # 39; || quote_ident (myseq.sequence_name) || & # 39 ;; & # 39 ;;
END OF LOOP;

END OF LOOP;

END;
 $$ LANGUAGE plpgsql;
EOF

Loop of the Turing machine and example of rejection

I am confused about these two. Rejecting the chain stops while the machine continues to spin.

My manual has an example on a rejection state and no physical example for the loop:

Suppose that no state of rejection has been given. And I grab a chain

$ 1 ^ {q_ {1}} $ 011

After all the transitions, the machine is now on the empty chain $ 1011 epsilon ^ {q_ {8}} $ with no other place to go and this is not about a state of acceptance, so that he rejects.

Now, consider if its on q2 to the chain $ 0 so $$ 10 ^ {q2} 11 $$

And it can not go anywhere. Does this also refuse? Or only if it is on the empty string?

Now what's a loop? My idea is

$$ 1 ^ {q_ {1}} 011 $$

$$ 1 ^ {q_ {2}} 011 $$

$$ 1 ^ {q_ {1}} 011 $$

$ points $

forever

Two actions in the body of the loop

Help me please, how can I write two actions in the body of the cycle "for"?

For example, if I have to write Print[] and add[] at each iteration.