Question Custom Implementation of Array

msinus

New member
Joined
Feb 22, 2019
Messages
4
Location
Sunnyvale
Programming Experience
1-3
Hello Friends, I am the new member of this group.

I just came to know about this forum and would like to thank the admin for creating this forum which helps the junior developers like me.

Recently, I had an interview question which I couldn't answer. How to implement array without using any data structures? I tried my best to do it, but I couldn't without using any in-built data structures.

If anyone has an idea how to do this, please help so that I can face the next interview with some confidence.

Thanks for your help.
 
It depends on exactly what they would consider an array implementation and what they would consider a data structure. You could, for instance, define a class that contained a reference to an object that contained a data element and a reference to another instance of the same type. You'd be creating a linked list without using any existing collection types, but I'm not sure whether that fits the description or not.
 
Thanks for your reply. I guess I got it what I need. Actually, they were looking for array implementation without using Array class. So I used array data type for the implementation
 
That seems rather weird. You almost never use the Array class directly in .NET code but every array is an instance of the Array class. For instance, if you do this:
C#:
var names = new string[10];
then you just created an instance of the Array class. You can prove it to yourself like this:
C#:
var names = new string[10];

Console.WriteLine(names is Array);
 
Actually, they were asking me to do the implementation of array without array class. They wanted me to implement all the properties of array from scratch like add,remove, find, length of the array etc.

I think I am clear about the question they asked and also the solution what I have found.
 

Latest posts

Back
Top Bottom