Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 825235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:13:21+00:00 2026-05-15T03:13:21+00:00

Yeah, it’s a homework question, so givemetehkodezplsthx! :) Anyway, here’s what I need to

  • 0

Yeah, it’s a homework question, so givemetehkodezplsthx! 🙂

Anyway, here’s what I need to do:
I need to have a class which will have among its attributes array of objects of another class. The proper way to do this in my opinion would be to use something like LinkedList, Vector or similar. Unfortunately, last time I did that, I got fire and brimstone from my professor, because according to his belief I was using advanced stuff without understanding basics.

Now next obvious solution would be to create array with fixed number of elements and add checks to get and set which will see if the array is full. If it is full, they’d create new bigger array, copy older array’s data to the new array and return the new array to the caller. If it’s mostly empty, they’d create new smaller array and move data from old array to new. To me this looks a bit stupid. For my homework, there probably won’t be more that 3 elements in an array, but I’d like to make a scalable solution without manually calculating statistics about how often is array filled, what is the average number of new elements added, then using results of calculation to calculate number of elements in new array and so on.

By the way, there is no need to remove elements from the middle of the array.

Any tips?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:13:22+00:00Added an answer on May 15, 2026 at 3:13 am
    class test {
        private Object[] objects;
        private int size;
    
        public test() {
            objects = new Object[10];
            size = 0;
        }
    
        public void push(Object o) {
            if (objects.length == size) {
                throw new RuntimeException("This wouldn't happen if I didn't have to reinvent the wheel");
            }
            objects[size] = o;
            size++;
        }
    
        public Object pop() {
            size--;
            Object o = objects[size];
            objects[size] = null;
            return o;
        }
    }
    

    Just kidding. I think you’re best bet is to implement your own linked list and then use that in your class. Something like:

    class Element {
        Object val;
        Element next;
        Element prev;
    
        public Element(Object val, Element next, Element prev) {
            this.val = val;
            this.next = next;
            this.prev = prev;
        }
    
    }
    
    class LinkedList {
        Element head;
        Element tail;
    
        public void add(Object o) {
            Element el = new Element(o, null, tail);
            tail.next = el;
        }
    
        public Object remove() {
            Element o = tail;
            tail = o.prev;
            tail.next = null;
            return o.val;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yeah, I know. Long title of question... So I have class name in string.
Yeah! its me again - seems like I have to ask you very often
Yeah, the noob question of the century... But in all seriousness, I actually have
Yeah, sorry about asking a stupid n00b question. So I have a C# program.
Yeah, I know this seems like a dumb question, its just a one-off hack
yeah :( simple question * blush * Lets imagine i have the following enumeration:-
This shows what I have and want: So yeah as you can see I
I have a very large list Suppose I do that (yeah, I know the
While I'm busy here reading the FastCGI documentation (yeah, reading the 'friendly' manual), does
So I have Visual Studio 2003 running on Windows 7 - yeah I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.