473,791 Members | 3,071 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sorting Arrays

Im trying to compare arrayindex slots in a array. I have an arraylist
of size (n) and once all the arraylist slots are filled i would like
to compare each slot so that they are all unique number.

Example: (455,453,456,43 5,437,333) this a unique arraylist
(455,435,455,45 5,422,222) this has multiple values and
will not work.

However in the code below it will loop through each slot however how
can i write code that will compare each slot against the other. I dont
need to worry about the condition of multiple number between slot 1
and slot 2. My only worry is multiple number on the next seqnetial
slot....below is that code i have started.

Public Sub SortArraylist()

For Each intarrayindex In _ReadingArrayLi st3
If (intarrayindex <intarrayinde x) Then

Else
End If
Next
End Sub

Sep 6 '07 #1
7 1286
cmdolcet69 wrote:
Im trying to compare arrayindex slots in a array. I have an arraylist
of size (n) and once all the arraylist slots are filled
*That's* the time to do the checking: when you're adding entries. If the
value already exists in the arraylist then don't add it.
i would like
to compare each slot so that they are all unique number.
Andrew
Sep 6 '07 #2
On Sep 6, 4:05 am, "Andrew Morton" <a...@in-press.co.uk.inv alid>
wrote:
cmdolcet69 wrote:
Im trying to compare arrayindex slots in a array. I have an arraylist
of size (n) and once all the arraylist slots are filled

*That's* the time to do the checking: when you're adding entries. If the
value already exists in the arraylist then don't add it.
i would like
to compare each slot so that they are all unique number.

Andrew
How would i do that check what code could i place in the existing code
would do that check for me.

Sep 6 '07 #3
cmdolcet69 wrote:
On Sep 6, 4:05 am, "Andrew Morton" <a...@in-press.co.uk.inv alid>
wrote:
>cmdolcet69 wrote:
>>Im trying to compare arrayindex slots in a array. I have an
arraylist of size (n) and once all the arraylist slots are filled

*That's* the time to do the checking: when you're adding entries. If
the value already exists in the arraylist then don't add it.
>>i would like
to compare each slot so that they are all unique number.

How would i do that check what code could i place in the existing code
would do that check for me.
Completely untested - check the syntax in the help:

' only add the new element if it is unique
If Not(myArrayList .Contains(newEl ement)) then
myArrayList.Add (newElement)
End If

Andrew
Sep 6 '07 #4
cmdolcet69 wrote:
Im trying to compare arrayindex slots in a array. I have an arraylist
of size (n) and once all the arraylist slots are filled i would like
to compare each slot so that they are all unique number.
No. Check for uniqueness as you /add/ each item - if it's already
present, don't add another one.
I can't recall if the ArrayList has a Contains() method; if not, you may
have to use a Dictionary-type class, say a HashTable or, if you have
VB'2005, use a List(Of Integer):

Dim aList as ArrayList ' or List(Of Integer)

If ( Not aList.Contains( value ) ) Then
aList.Add( value )
End If

HTH,
Phill W.
Sep 6 '07 #5
Phill W. wrote:
cmdolcet69 wrote:
>Im trying to compare arrayindex slots in a array. I have an arraylist
of size (n) and once all the arraylist slots are filled i would like
to compare each slot so that they are all unique number.

No. Check for uniqueness as you /add/ each item - if it's already
present, don't add another one.
I can't recall if the ArrayList has a Contains() method; if not, you
may have to use a Dictionary-type class, say a HashTable
Just a comment: if the OP used a HashTable, there would be no duplication
issue because

myHashTable(val ue)=value

adds it if it isn't there already, and overwrites it if it is there.

Andrew
Sep 6 '07 #6
Like this
Dim Ht As New Hashtable()
Dim dummyArr() As Integer = {100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 100,
100, 3, 0, 4, 5, 5}
For Each val As Integer In dummyArr
Ht(val) = val
Next
'proove that all items are filtered

For Each val As Integer In Ht.Values
Debug.WriteLine (val)
Next
regards

Michel

"Andrew Morton" wrote:
Phill W. wrote:
cmdolcet69 wrote:
Im trying to compare arrayindex slots in a array. I have an arraylist
of size (n) and once all the arraylist slots are filled i would like
to compare each slot so that they are all unique number.
No. Check for uniqueness as you /add/ each item - if it's already
present, don't add another one.
I can't recall if the ArrayList has a Contains() method; if not, you
may have to use a Dictionary-type class, say a HashTable

Just a comment: if the OP used a HashTable, there would be no duplication
issue because

myHashTable(val ue)=value

adds it if it isn't there already, and overwrites it if it is there.

Andrew
Sep 6 '07 #7
On Sep 6, 7:03 am, "Andrew Morton" <a...@in-press.co.uk.inv alid>
wrote:
cmdolcet69 wrote:
On Sep 6, 4:05 am, "Andrew Morton" <a...@in-press.co.uk.inv alid>
wrote:
cmdolcet69 wrote:
Im trying to compare arrayindex slots in a array. I have an
arraylist of size (n) and once all the arraylist slots are filled
*That's* the time to do the checking: when you're adding entries. If
the value already exists in the arraylist then don't add it.
>i would like
to compare each slot so that they are all unique number.
How would i do that check what code could i place in the existing code
would do that check for me.

Completely untested - check the syntax in the help:

' only add the new element if it is unique
If Not(myArrayList .Contains(newEl ement)) then
myArrayList.Add (newElement)
End If

Andrew
If there are a lot of items in the array list it might help to keep
them in a Dictionary as well to facilitate a quicker check.

Sep 6 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2986
by: Paul Kirby | last post by:
Hello All I am trying to update me code to use arrays to store a group of information and I have come up with a problem sorting the multiple array :( Array trying to sort: (7 arrays put into an array) and I want to sort on Descending. This is displayed using print_r() function. Array
7
3267
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) CType(local4, Short) = CType(src, Short)
22
4172
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b) { return -1; } else
7
3050
by: Karin Jensen | last post by:
Hi I am running a PHP program that connects to an Access 2000 database via ODBC: $results = odbc_exec($connection_id, $sql_select); Is it possible to sort the contents of $results? I wish to use a regex-based sort order that you can't do in Access 2000* SQL with "ORDER BY".
16
3393
by: aruna | last post by:
Given a set of integers, how to write a program in C to sort these set of integers using C, given the following conditions a. Do not use arrays b. Do not use any comparison function like if/then or switch-case c. you can use pointers only d. you cannot use any of the loops either.
23
6353
by: yatindran | last post by:
hai this is my 2d array. int a = { {5,2,20,1,30,10}, {23,15,7,9,11,3}, {40,50,34,24,14,4}, {9,10,11,12,13,14}, {31,4,18,8,27,17}, {44,32,13,19,41,19}, {1,2,3,4,5,6},
10
455
by: Roy Gourgi | last post by:
Hi, How would I sort an array? TIA Roy
3
2193
by: SneakyElf | last post by:
i am very green with c++ so i get stuck on very simple things anyway, i need to write a program that would read data from file (containing names of tv shows and their networks) one line at a time ( ; separates tv show and network) sort the strings according to the network and according to the show. and so: //to open file - ifstream myFile;
3
7347
KevinADC
by: KevinADC | last post by:
If you are entirely unfamiliar with using Perl to sort data, read the "Sorting Data with Perl - Part One and Two" articles before reading this article. Beginning Perl coders may find this article uses unfamiliar terms and syntax. Intermediate and advanced Perl coders should find this article useful. The object of the article is to inform the reader, it is not about how to code Perl or how to write good Perl code, but to teach the Schwartzian...
5
3188
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The search algorithms that can be used are Linear Search and Binary Search. The sorting algorithms are bubble, selection and Insertion sort. First, the user is asked whether he/she wants to perform a search option, a sort operation, or exit the program. If...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.