Professional Documents
Culture Documents
Pseudo Code
Pseudo Code
Jehad Aldahdooh
Faculty of Engineering DataStructure and Algorithms
Computer Engineering Dept. HW #1 Solution
v.setNext(head);
head=v;
R3.10: Give an algorithm for finding the penultimate node in a singly linked list
where the last element is indicated by a null next reference.
Pseudo code
1
Chapter 3: Arrays, Linked lists, and Recursion Eng.Jehad Aldahdooh
C-3.7: Describe a fast recursive algorithm for reversing a singly linked list L, so
that the ordering of the nodes becomes opposite of what it was before.
Pseudo code
How to call it
2
Chapter 3: Arrays, Linked lists, and Recursion Eng.Jehad Aldahdooh
C3.9: Give a fast algorithm for concatenating two doubly linked lists Land M, with
header and trailer sentinel nodes, into a single list L'.
Pseudo code
C3.13: Describe a recursive method for converting a string of digits into the integer
it represents. For example, 1113531 11 represents the integer 13,531
temp += s[count]; }
int n = temp.length() - 1;
if(temp.empty()) {
return 0;}
else { return 0; }
3
Chapter 3: Arrays, Linked lists, and Recursion Eng.Jehad Aldahdooh
C3.18: Write a short recursive Java method that will rearrange an array of int
values so that all the even values appear before all the odd values.
C3.18A.java
4
Chapter 3: Arrays, Linked lists, and Recursion Eng.Jehad Aldahdooh
طريقة تانية
C3.18B.java
Extra Exercises
5
Chapter 3: Arrays, Linked lists, and Recursion Eng.Jehad Aldahdooh
C3.19: Write a short recursive Java method that takes a character string s and
outputs its reverse. So for example, the reverse of "pots&pans" would be
"snap&stop".
Reverse.java
C-3.6 Give a recursive algorithm to compute the product of two positive integers,
m and n, using only addition and subtraction.
Product.java