Fortran Fortran help: deleting items from a list

  • Thread starter Thread starter brad sue
  • Start date Start date
  • Tags Tags
    Fortran List
AI Thread Summary
The discussion revolves around writing a Fortran 77 function named "delete" that removes a user ID from an integer array. The function should return 0 for successful deletion, -1 if the list is empty, and -2 if the ID is not found. A user shared their initial code attempt but expressed confusion about implementing the necessary checks for an empty list and for confirming whether the ID exists in the list. The solution provided suggests first checking if the list length (n) is zero to determine if it is empty. Additionally, it recommends initializing the variable "indexe" to 0 before the loop that searches for the ID. If "indexe" remains 0 after the loop, it indicates that the ID was not found in the list. This approach helps in structuring the function correctly to handle the specified conditions.
brad sue
Messages
270
Reaction score
0
Hi , I need help to write a code for this function(fortran 77):

integer function delete(id, list, n) where
• delete returns 0 if the deletion was successful, -1 if the list is empty, and -2 if the user is not currently in the list.
•id is the integer identification number of the user.
•list is the integer array from which the id is to be removed.
•n is the current length of the list.

I tried this:
Code:
    integer function delete(id,list,n)
     integer i,indexe,j
     do 20 i=1,n
     if(list(i).EQ.id) then
          indexe=i

20    continue
         do 30 j= indexe,n
          list(i) = list(i+1)
30        continue
      n = n-1
     return 0
I have not finfished because I am stuck . I don't know where to introduce the else statement that would indicat the id is not in the list.
My second problem is that How to check if that array is empty?

please can someone help me?
Thank you for the time.
 
Technology news on Phys.org
The first thing to do is to check if the list is empty, i.e., n.eq.0.

To check if id is not in the list, set indexe to 0 before the first loop and check if it is still 0 after the loop.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
3
Views
2K
Replies
29
Views
3K
Replies
12
Views
3K
Replies
0
Views
320
Replies
8
Views
4K
Replies
2
Views
2K
Back
Top