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)

## All 4 Replies

1. Show some effort of your own.
2. We will help you work out any issues with your solution.

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?

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

I stand corrected. Thanks for pointing out that this can be done. I agree about Algol 68, though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.