-2

1.write an algorithm to count the no of items in a queue
2.write an algorithm that searches a given item of information in a simple linked list
(using algol or fortran)

4
Contributors
4
Replies
28
Views
4 Years
Discussion Span
Last Post by Schol-R-LEA
1
  1. Show some effort of your own.
  2. We will help you work out any issues with your solution.
0

Wait a moment, how old is the textbook you are using? While Fortran is still in use - though in a form completely different from it's predecessors - Algol 60 and Algol 68 are long dead. Also, neither Algol 60 nor most older FORTRAN compilers have pointers, or structures for that matter, and thus cannot implement linked lists in the first place. WTF?

1

re: Linked lists can be implemented in fortran.

COMMENT re: "nor ... FORTRAN compilers have pointers"
Simply declare a large array of CHARACTER and use an INTEGER offset into the array as a pointer. Lets call it a HEAP. e.g.
PARAMETER(SIZEOF HEAP=1000000)
INTEGER FREE HEAP/1/
CHARACTER*(SIZEOF HEAP) HEAP

COMMENT re: "nor structures for that matter"
* Use a named COMMON for defining structures. (effectively creating C's 'union's) e.g.
CHARACTER NAME*(20), ADDDRESS*(40)
REAL BALANCE
INTEGER NEXT CUST

COMMON/CCUST/NAME,ADDRESS,BALANCE,NEXT CUST

* Then use EQUIVALENCE for each 'struct'ure type to map this COMMON memory to a second short CHARACTER array.
CHARACTER CUST
PARAMETER(SIZEOF CUST=20+40+4+4)
EQUIVALENCE(NAME, CUST)

* Now MANUALLY add some links to the link list, should be done in a SUBROUTINE 'APPEND'
NAME='Micheal Jackson'
ADDRESS='US'
BALANCE=123.45
NEXT=FREE HEAP+SIZEOF CUST

HEAP(FREE HEAD:FREE HEAP+SIZEOF CUST-1)=CUST
FREE HEAP = FREE HEAP + SIZEOF CUST

NAME='Elvis Presley'
ADDRESS='US'
BALANCE=678.90
NEXT=FREE HEAP+SIZEOF CUST

HEAP(FREE HEAD:FREE HEAP+SIZEOF CUST-1)=CUST
FREE HEAP = FREE HEAP + SIZEOF CUST

* etc

Of course you actually have to do the above using code only 6 letter variable names....

Good luck
NevilleDNZ

re: SUBROUTINE....
Nowdays, the only place I hear the word "SUBROUTINE" used is in StarTrek on TV. Using it makes me feel like I just graduationed from StarFleet Academy.

p.s. Algol68 is much easier then Fortran77, c.f. http://algol68.sourceforge.net/ for a compiler for:
MS Windows, Cygwin, Debian, Ubuntu, Centos, RedHat, FreeBSD, NetBSD & Mac OS X.

And for list of example code URLs c.f.
http://rosettacode.org/wiki/User:NevilleDNZ#ALGOL_68_Contributions

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.