How to verify that the limit of a vector has not been exceeded?

Asked

Viewed 34 times

-2

Good afternoon, gentlemen!

I’m doing a college paper that asks me to create an agenda. I did most of the code, but I’m not able to see the light so that when the user tries to register a person in the agenda, show if the agenda is already full or not.

Follow the statement, I can post the whole code here, but it’s too big.

"g) Set a block of instructions inserts person: Inserts by alphabetical order of name moves all following elements from the vector to the later position. (When inserting should-severify if the vector boundary will not be exceeded in case of printing the message AGENDACHEIA); "

  • If the code is too big, follow the tips of this page to reduce it. Having done this, it is enough [Edit] question and add code

1 answer

0

If the vector has static size (I’m going to assume yes, since there is a limit), you set the size at some point, right? For example, I will consider the following:

#define MAXTAM 100

Having this constant you can use it to do checks, for example if there is a stop condition it can be i <= MAXTAM.

If this is not possible, another possible solution may be to set a fixed value for the last position (in the same way as the \0 is used to check the end of a string). Then after inserting you see if the value of the last position remains the established fixed value or changed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.