![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2006
Posts: 120
Rep Power: 3
![]() |
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 |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
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)
ENDNote: the code may be indented badly as I've typed it quickly, but shows the idea. |
|
|
|
|
|
#3 | |
|
Hobbyist Programmer
Join Date: Mar 2006
Posts: 120
Rep Power: 3
![]() |
Quote:
Thank you. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|