Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (6 votes)
See more:
The array i have declared is:
int[] set = new int[] { 1, 2, 3, 4, 5 };

I have to write code for the two functions below without using any libraries and no LINQ.
I am struggling and have no idea where to start.

clear_set : removes all elements from the set; returns nothing.

is_empty : checks whether the set is empty and returns the Boolean value true or false, accordingly.

Hopefully someone can help.

Thanks.

What I have tried:

I have not tried anything yet. I'm sat staring at visual studio wandering how I am going to approach this.
Posted
Updated 13-Apr-17 13:39pm

We do not provide free services with homeworks, you have to do it yourself. However, these are basic arrays and to remove the elements means to set them to null — but how can you set a value type to null in C#? That question is the first answer.

Also, if an array is empty, it means it has no elements in it. There is a property, Length, that you can use and then return a value indicating whether the array is empty or not. This is the answer to your second question. Code them out.

Whenever, you find yourself in a trouble related to C# programming, go to this documentation tutorial and read the sections of it. C# Programming Guide[^]. It is my recommendation to anyone starting to learn C#.
 
Share this answer
 
It would have taken less time to Google such phrases as "C# clear array" and "C# check array is populated" than it would to have typed out the question.

Ironically, it would also take less time for me to write the code than to write this answer but I'm not going to do your homework for you.

The thing with laziness is that it becomes counterproductive when you spend more time avoiding work than doing it. If you're no good at being lazy, learning to code might be a good back-up plan.
 
Share this answer
 
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.

The idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements." BusinessDictionary.com[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900