Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How to implement an arraylist without using java.util.arraylist?

I want to know how the adt interface and adt classes work instead of just using the premade package, before someone says its better to use the pre-defined package i already know how to but i wanna know how it works without it

thanks

2 Answers

Relevance
  • 8 years ago
    Favorite Answer

    If you want to see the actual code that each API uses, look inside your JDK folder for the src.zip. Refer to the javadocs of the API to discover the path to the framework you are interested in, e.g. open folders /java/util/ArrayList.java

  • ?
    Lv 4
    4 years ago

    the difficulty in sorting 'ArrayList' manually is that we ought to write down separate purposes for each records style. basically see the implementation for a 'long' records style: public int median(long x[], int a, int b, int c) { return (x[a] < x[b] ? (x[b] < x[c] ? b : x[a] < x[c] ? c : a) : (x[b] > x[c] ? b : x[a] > x[c] ? c : a)); } public void replace(long x[], int a, int b) { long t = x[a]; x[a] = x[b]; x[b] = t; } public void vectorswap(long x[], int a, int b, int n) { for (int i=0; i<n; i++, a++, b++) replace(x, a, b); } //speedy form implementation of Sorting the records public void form(long x[], int off, int len) { if (len < 7) { for (int i=off; i<len+off; i++) for (int j=i; j>off && x[j-a million]>x[j]; j--) replace(x, j, j-a million); return; } int m = off + (len >> a million); if (len > 7) { int l = off; int n = off + len - a million; if (len > 40) { int s = len/8; l = median(x, l, l+s, l+2*s); m = median(x, m-s, m, m+s); n = median(x, n-2*s, n-s, n); } m = median(x, l, m, n); } long v = x[m]; int a = off, b = a, c = off + len - a million, d = c; on an identical time as(real) { on an identical time as (b <= c && x[b] <= v) { if (x[b] == v) replace(x, a++, b); b++; } on an identical time as (c >= b && x[c] >= v) { if (x[c] == v) replace(x, c, d--); c--; } if (b > c) destroy; replace(x, b++, c--); } int s, n = off + len; s = Math.min(a-off, b-a ); vectorswap(x, off, b-s, s); s = Math.min(d-c, n-d-a million); vectorswap(x, b, n-s, s); if ((s = b-a) > a million) form(x, off, s); if ((s = d-c) > a million) form(x, n-s, s); } Parameters: x[] - array to form --> ArrayList==> obj.toArray() off - Offset --> commencing component in Array from the place sorting starts off (regularly 0). len- length --> form of factors to form from Offset (length()). as a replace of 'long' records style, basically attempt 'merchandise' records style.

Still have questions? Get your answers by asking now.