Vector based on Array : Vector « Data Type « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » Data Type » Vector 
Vector based on Array


<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT language="JavaScript">

// Vector Class

// Constructor
function Vector(size) {
  if (size == 0) {
    size = 10;
  }
  this.theArray = new Array(size);
  this.index = 0;

}

// size() -- returns the size of the vector
function size() {
  return this.theArray.length;
}

// getElement() -- returns the current element
function getElement() {
  if (this.theArray != null) {
    return this.theArray[index];
  }
}

// getLastElement() -- returns the last element
function getLastElement() {
  if (this.theArray{this.theArray.length - 1!= null) {
    return this.theArray[this.theArray.length - 1];
  }
}

// getFirstElement() -- returns the first element
function getFirstElement() {
  if (this.theArray[0!= null) {
    return this.theArray[0];
  }
}

// addElement() -- adds a element at the end of the Vector
function addElement(vObject) {
  if(this.theArray.length == this.index) {
    resize(10);
  }
  
  this.theArray[index= vObject;
}

// addElementAt -- adds a element at a certain index of the Vector
function addElementAt(vObject, i) {
  while (this.theArray.length <= i) {
    resize(10);
  }
  
  this.theArray[i= vObject;
}

// removeElementAt() -- removes and returns the element at a certain index  
function removeElementAt() {
  
}

// removeAllElements() -- removes all elements in the Vector
function removeAllElements() {
  delete this.theArray
}

// resize() -- increases the size of the Vector
function resize() {

}

// toString() -- returns a string rep. of the Vector
function toString() {

}

</SCRIPT>
</HEAD>

           
       
Related examples in the same category
1. To have a dynamic collection instead of using arrays when the total quantity is unknown
w_ww___.__j_a__v__a_2___s___.co__m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.