Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-06-2003, 06:37 AM   #1 (permalink)
Apodysophilia
Regular Contributor
 
Apodysophilia's Avatar
 
Join Date: Apr 2003
Location: noWhere, PA
Posts: 104
Apodysophilia is on a distinguished road
Send a message via AIM to Apodysophilia
Question delete parts of an array

Code:
 int[] ary ={6,2,3,4,5,8,9,1,2,12}
how would i delete something like the 3 cell, or any cell?
Apodysophilia is offline   Reply With Quote
Old 05-06-2003, 11:53 AM   #2 (permalink)
EscapeCharacter
GNU/Punk
 
EscapeCharacter's Avatar
 
Join Date: Jul 2002
Location: stuffs
Posts: 66
EscapeCharacter is on a distinguished road
Send a message via AIM to EscapeCharacter
you cannot do what you are asking arrays are not dynamic, you would have to change the array a list of pointers something like
Code:
struct node{
        int num;
        struct node *next;
};
then have a delete function that would go like this
Code:
void delete(int place, struct node *list){
        int count = 0;
        struct node *tmp = list;
        struct node *tmp2;
        for(count; count < place; count++){
                tmp = tmp->next;
        }
        tmp2 = tmp;
        tmp2 = tmp2->next;
        tmp->next = tmp2->next;
        free(tmp2);
}
well something like that it looks a little off to me but you should get the gist.

edit: disregard this post, i thought this was in the c/c++ section
__________________
cd /usr/ports/misc/life && make install
EscapeCharacter is offline   Reply With Quote
Old 05-06-2003, 12:22 PM   #3 (permalink)
Apodysophilia
Regular Contributor
 
Apodysophilia's Avatar
 
Join Date: Apr 2003
Location: noWhere, PA
Posts: 104
Apodysophilia is on a distinguished road
Send a message via AIM to Apodysophilia
Quote:
Originally posted by EscapeCharacter
edit: disregard this post, i thought this was in the c/c++ section
ok, well anyone else? can i even do that?

Apodysophilia is offline   Reply With Quote
Old 05-06-2003, 12:39 PM   #4 (permalink)
ender
Code Monkey
 
ender's Avatar
 
Join Date: Mar 2003
Location: Evansville, IN
Posts: 75
ender is on a distinguished road
Send a message via AIM to ender Send a message via Yahoo to ender
Sure

Sure, you can do it, I looked into the Java API documentation, and even though you can't modify the size of the array that you are deleting from, you can just shift all the elements so you have an empty space at the end. Like so:

Code:
int[] ary = { 1, 2, 3, 4, 5 };
int elementIndexToDelete = 2;

for (int i = elementIndexToDelete; i < ary.length - 1; i++) {
   ary[i] = ary[i+1];
}

ary[ary.length - 1] = 0;
This would make the 3 dissapear. I'm not sure about the empty space at the end though, don't know if you can get rid of that somehow. I suppose you could just keep around a local variable called size to let you know how big it really is...because length won't change.

For the dynamic capability, Java includes something called Vector, look into it, it allows stuff to be removed from it, but you might have to initialize it differently than you do. It is similiar to the STL in C++ and is a collection framework.

The Documentation

This is my best guess, hope it helps.

Ted Morse
__________________
while(1) fork();
ender is offline   Reply With Quote
Old 05-07-2003, 12:11 PM   #5 (permalink)
Apodysophilia
Regular Contributor
 
Apodysophilia's Avatar
 
Join Date: Apr 2003
Location: noWhere, PA
Posts: 104
Apodysophilia is on a distinguished road
Send a message via AIM to Apodysophilia
thanks ender that worked great
Apodysophilia is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
working with Array Goong MS Technologies ( ASP, VB, C#, .NET ) 3 07-22-2004 12:14 PM
breaking down an array from a form metazai PHP 12 07-09-2004 06:18 AM
array max num Apodysophilia Java 9 04-10-2003 06:36 AM
Array of chars of chars of, wait, uh... anon Standard C, C++ 15 01-11-2003 04:15 PM
adding to an array in php sde PHP 1 06-12-2002 11:04 AM


All times are GMT -8. The time now is 09:56 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting