Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 19th, 2006, 11:32 PM   #1
brad sue
Hobbyist Programmer
 
Join Date: Mar 2006
Posts: 120
Rep Power: 3 brad sue is on a distinguished road
array manipulation

Hi ,
I want to write a function in FOTRAN 77 that delete an element of a list. My problem is I dont know what to put in the element cell to erase.

if my list is LIST(15), I want to delete the 15th elememt, can I overwrite the value of the 15th element by that of that 16th and have have all element back one cell in the array?

Thank you
B
brad sue is offline   Reply With Quote
Old Apr 20th, 2006, 4:52 AM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
I'm not sure I've fully understood your question.

In Fortran, it is not possible to remove an element of an array; the size of an array is fixed at compile time. What you need to do is shuffle elements down, and keep track of the total length. For example;
        integer list(20)
        integer length
C
C    populate
C
        do 10 i = 1,20
            list(i) = i
    10 continue
        length = 20
C
C      we want to remove element 15
C

       do 20 i = 15, length
           list(i) = list(i+1)
   20 continue
       length = length-1

     write(*,*) (list(i), i = 1, length)
     END
This will print the values 1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 17 18 19 20 (+/- whitespace).

Note: the code may be indented badly as I've typed it quickly, but shows the idea.
grumpy is offline   Reply With Quote
Old Apr 20th, 2006, 2:56 PM   #3
brad sue
Hobbyist Programmer
 
Join Date: Mar 2006
Posts: 120
Rep Power: 3 brad sue is on a distinguished road
Quote:
Originally Posted by grumpy
I'm not sure I've fully understood your question.

In Fortran, it is not possible to remove an element of an array; the size of an array is fixed at compile time. What you need to do is shuffle elements down, and keep track of the total length. For example;
        integer list(20)
        integer length
C
C    populate
C
        do 10 i = 1,20
            list(i) = i
    10 continue
        length = 20
C
C      we want to remove element 15
C

       do 20 i = 15, length
           list(i) = list(i+1)
   20 continue
       length = length-1

     write(*,*) (list(i), i = 1, length)
     END
This will print the values 1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 17 18 19 20 (+/- whitespace).

Note: the code may be indented badly as I've typed it quickly, but shows the idea.
yes it is what I want to do.
Thank you.
brad sue is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC