Recursion Help
Ok, Our Assignment is, find the kth smallest item in an array using recursion. I have been reading the text, and it says that I need to have a "pivot point" somewhere in the array and then sort each array on either side of the pivot. Right now, I have picked out a pivot which is pretty much in the middle of the array not matter how big it is. Now I am trying to make two separate arrays, one array that is from index 0 of the array to the pivot -1 and another array that is from pivot + 1 to the last index of the array. After that I think I will try to use some kind of sort method to sort each of the smaller arrays. Anyhow, right now I am stuck on making the new array, from 0 to pivot - 1. If you need more explanation of what I am trying to do, please ask. An example would be: if I make my array from 0 - 999, my pivot would be 499 and I am trying to make a new array from 0 - 498 (this excludes the pivot). When I test my program, it gives me an error saying the array is out of bounds, I have kinda a clue what the means but I just cant figure out why it is happening, and I strongly feel it has something to do with this code I am showing you. I am wondering about my base case as well, could there be something wrong with the base case? If this makes no sense, I will try to answer your questions, or if that does not work I will post the whole code, but I am trying to refrain from posting the whole code due to other classmates might be on here stealing my code! Thanks in advance
public static int[] arrPartition1(int[] fillerArr, int first, int pivotInd){
int[] firstHalfArray;
firstHalfArray = new int[pivotInd - 1];
if(first < pivotInd - 1)
return firstHalfArray;
if(first < pivotInd)
firstHalfArray[first] = fillerArr[first];
first++;
return arrPartition1(fillerArr, first, pivotInd);
}
and here is my whole program. it compiles, but there is the runtime error. and i am kind of clueless on what i am doing wrong here -
import java.util.*;
public class TEST
public static void main(String[] args)
Scanner scan = new Scanner(System.in);
int n = 10;
int k = 2;
int first = 0;
int last = 0;
int kth = 0;
// n = scan.nextInt();
// k = scan.nextInt();
int[] dA = new int[n];
for(int i=0; i<n ; i++)
dA[i] = (int) Math.round(1000*Math.random());
System.out.println("array elements:" + dA);
first = 0;
last = n-1;
quickSort(dA, first, last);
for(int i=0; i<n; i++)
System.out.println("sorted array: entry at "+i+" :" +dA[i]);
// kth = kSmall(k, dA, first, last);
// System.out.println(kth);
public static void quickSort(int[] dA, int first, int last)
int pivotIndex =1 ;
// if(last<= first)
// return;
if(first<last)
quickSort(dA, first, pivotIndex-1);
quickSort(dA, pivotIndex+1, last);
public static int kSmall(int k, int[] dA, int first, int last)
int pivotIndex = 5;
if(k < (pivotIndex - first + 1))
return kSmall(k, dA, first, pivotIndex-1);
else if(k==(pivotIndex-first+1))
return dA[pivotIndex];
else
return kSmall(k-(pivotIndex-first+1), dA, pivotIndex+1, last);
Edited by: aberrated on Feb 9, 2008 9:47 PM
Similar Messages
-
Recursions help?!?!
Go here please: http://www.javabat.com/prob/p138907
So i have already written the code but a single condition does not work. Any help? I get a out of bounds exception. Here's the code:
public boolean groupSum5(int start, int[] nums, int target) {
if(start=nums.length)
return(target==0);
if(groupSum5(start 1, nums, target-nums[start]))
return true;
if(nums[start]%5==0&&nums[start 1]!=1)
return groupSum5(start 1, nums, target-nums[start]);
if(groupSum5(start 1, nums, target))
return true;
else
return false;
}Sorry for posting links and not indenting, i'm used writing this way.
Okay, so instead of going the Javabat to compile and check i guess the hard way is the way to go. The problem is that i need to check if there's a 1 on the right of a 5 in a given array. Cannot change the sequence of the array. I need to add the numbers in the array accordingly so that it will equal target (i.e. target is 15 or 7). So if i have {2, 5, 10, 4} with a target of 19 it is possible is reach the target by adding 5,10, and 4. No there's a constraint, if a number is a multiple of 5 it MUST BE ADDED no matter what, and finally here's my problem that i can't solve: in the above i said if there's a 1 on the right of a 5, well if this happens i cannot add the 5. So {3, 5, 1} with a target of 9, it looks like you can add all the numbers and get 9 but you can't because of the constraint of a 1 right of a 5. So what i did was a if statement if(nums[start]%5==0&&nums[start+1]!=1) then it will execute the lines in the if statement. Problem is that there's a "out-of-bounds" exception because of the num[start+1] (it checks if the next element is a one or not). Can anyone fix this if statement or whether i need a new one?? Also another note, this is all recursions, i have no i dead why this can't be in a for loop!! but the chapter in my CS1 class is recursions so recursions are required. Thank you. -
Iterator recursion help needed
there is a recursion example in my text book. it is a bit difficult for me. so i thought i would type it out and follow the progress of the code in the debugger to get a better understanding of how it works. trouble is, i can't figure out what kind of statement in a simple test class will get it working and actually PRINTING out all the permutations.
the example code takes any given word and is supposed to spit out all the permutations of the word. for example, the user defined word might be "key". the program should print out . . .
key
kye
eky
eyk
yke
yek
ordinarily, i wouldn't be so dead set on understanding this example, but it is essential that i do.
the book gives the class that has the recursion interator, but if someone could help me out with a bit of code (i know it must only be a line or two) that will start up the iterator to give me the results.
the code is
public class PermuteString {
private String word;
private int index;
private PermuteString substringGenerator;
public PermuteString(String s) {
word = s;
index = 0;
if (s.length() >1) {
substringGenerator = new PermuteString(s.substring(1));
public String nextPermutation() {
if (word.length() == 1) {
++index;
return word;
else {
String r = word.charAt(index) +
substringGenerator.nextPermutation();
if (!substringGenerator.morePermutations()) {
++index;
if (index < word.length ()) {
String tailString = word.substring(0, index) +
word.substring(index + 1);
substringGenerator = new PermuteString(tailString);
return r;
public boolean morePermutations() {
return index < word.length();
if anyone could give me a bit of code to put into a test to get this thing running, i might get a little headway into understanding it.
thanks
crquickCreate an instance of PermuteString, passing it the String you want to permutate. While it has morePermutations(), print the nextPermutation().
PermuteString p = new PermuteString("key");
while (p.morePermutations()) {
System.out.println(p.nextPermutation());
} -
Recursive Help!!!!
I was given the assignment of writing a recursive method for finding the median of an array and I am having a great deal of difficulty. This is what I have so far and I am thinking that this is not even the way to go about solving for the median. Can anyone help me please????
public static int median( double [] A, int i, int j, int k)
if (A[i] < =A[j] )
if ( A[j] <= A[k] )
return j ;
else if ( A[i] < = A[k] )
return k ;
else
return i ;
else // A[j] < A[i]
if ( A[i] <= A[k] )
return i ;
else if ( A[j] < = A[k] )
return k ;
else
return j ;First, when you post code, please use [code] and [/code] tags as described in Formatting Help on the message entry page. It makes it much easier to read.
Second, can you describe the recursive algorithm without using Java? E.g. in plain ol' English, or pseudocode, or a mathematical notation.
For example, the classic recursion example, factorial (!) :
For non-negative integers N:
If N == 0, then N! is 1
If N > 0, then N! = N * ((N-1)!)
Make sure you understand the following without regard to Java:
* How your algorithm is defined in terms of itself (e.g., how the median of the array is based on the median of a subset of the array)
* What the non-recursive, fundamental case is (e.g., the median of a single element is that element)
So, are you having trouble with the recursive nature of the problem, or with the mechanics of how to express that in Java? -
Recursion Help (I don't get this)
I feel so stupid. I just can't understand recursion.
public static int fib(int n)
int result;
if (n <=2)
result = 1;
else
result = fib(n-1) + fib(n-2);
return result;
}The above is the famous Fibonacci method. But I DON'T GET IT. How the heck does this work? I don't understand how the recursive case works (result = fib(n-1) + fib(n-2)).
The way I understand it:
If we were to call call fib(5)...
recursive case:
result = fib(n-1) + fib(n-2); -> 4 + 3
The result would be 7, and then we would be done because we've reached the base case (n <=2). The correct answer is 5, so I'm obviously wrong. I just can't grasp this key concept. I'm feeling very noobish. :(I should add that recursion is related to
mathematical induction, a powerful tool in
mathematics.
And once you get used to thinking about recursion,
you should see that in many ways recursive solutions
are simpler and clearer than non-recursive approaches.Ever so true but an efficient recursive solution should use a stack of
depth log(n), where n is the problem size, at most. It should also not
recompute what has been computed before.
The naive recursive fibonacci function doesn't fit that bill: it uses a stack
of size n for the calculation of fib(n) and it recalculates what has been
calculated before many times.
kind regards,
Jos -
i know this is trivial code, that is simple yet i cant get it
i have the following method
public static void let(char x){
if (x == 'a')
return;
x = (char) ((int) let('a' + 1));
System.out.print(x + " ");
here is the error i get
"let(char) in lab7 cannot be applied to (int)
any help will be appreciatied and i will award duke dollars to it
thank youOne more thing: the call let('a'+1);
You are adding a char (16-bit) to an int (32-bit), so the result will be int. That's why the error message says "let(char) cannot be applied to (int)".
To avoid it, do a cast: let((char)('a'+1)); -
Recursion(Recursion)help
HI all
I am a bit confused about how recursion actually works. consider this code:
class Mystery
public static void main(String[] args)
System.out.println(mystery(5,2));
static int mystery (int a, int b)
if(a==0) return 1;
else return b * mystery(a - 1, b);
}The answer is 32, but why? i though it would do 2*4*3*2*1, but it doesn't. Could anybody tell me why?
Thank youthink of recursion as diggin, you need to get deeper and deeper till you hit the exit condition (that which does not cause more diggin and returns a base value).
Think of this as the programs trace (line numbers in front)
1: mystery(5,2)
2: else return 2 * mystery(4, 2);
3: else return 2 * mystery(3, 2);
4: else return 2 * mystery(2, 2);
5: else return 2 * mystery(1, 2);
6: else return 2 * mystery(0, 2);
7: if(a==0) return 1;
once you reach the last line, it backward substitutes the return values up the chain. so....
line 6 becomes -> else return 2 * 1;
line 5 becomes -> else return 2 * (2 * 1);
so on and so forth. One thing to make sure when you create a recursive method is to have a proper exit condition. There has to be a base case that allows the recursion to cease, in this case the "if(a==0) return 1;" -
public class LinkedList<T>{
private Node head;
public LinkedList()
head = null;
public boolean isEmpty()
return (head==null);
public void addToHead(T val )
Node n = new Node(val);
n.next = head;
head = n;
public T getHeadData(){
if(head == null){
throw new RuntimeException("attempt to get data from an empty list !");
else{
return head.data;
public void deleteHead(){
if(head == null){
throw new RuntimeException("Deleting from an empty list !");
}else{
head= head.next;
public void addToTail(T val)//show no result
Node n = new Node (val);
if(head==null)
head = n;
else{
Node curr = head;
curr = curr.next;
curr.next = n;
addToTail(val);
}//end addtail
public void delete(T val){//does not return a result (shows no errors)
Node curr=null;
if(head !=null){
if(head.data==val)
head = head.next;
else{
curr = head;
curr = curr.next;
delete(curr.data);
public void insertSorted(T val){
Node y = new Node(val);
if(head==null || val < head.data)//operator < cannot be applied to T, T
head = y;
else
head = head.next;
insertSorted(head.data);
public boolean contains(T val)
if(head!=null){
if(head.data==val)
return true;
head = head.next;
return contains(val);
return false;
}//end of contains
public String toString(){
String str = " ";
Node curr = head;
while(curr !=null){
str = str + curr.data +" ";
curr = curr.next;
return str + "\n";
public class Node{
public T data;
public Node next;
public Node(T val){
data = val;
next = null;
}//End of node class
}//Linked List
class TestLinkedList{
public static void main(String[] args){
LinkedList<Integer>ST = new LinkedList<Integer>();
for(int i = 0; i < 10; i++){ //correctly load linkedlist
ST.addToHead(i);
System.out.println(ST.toString()); //print list
boolean y = ST.contains(12);
System.out.println(y);
ST.addToTail(200); //returns nothing
System.out.println(ST.toString());
ST.delete(5);
System.out.println(ST.toString());
insertSorted(11);
System.out.println(ST.toString());
}//end main
}//end class
Need help.
public void addToTail(T val)
public void delete(T val)
public void insertSorted(T val)
I need help to get the above functions to work recursively. I am able to get them work iteratively, no problem. When I try to write the functions re cursively, I am not able to see any results. I am at a lost understanding why.Well, your addToTail, for one, makes no sense. What do you think it's doing when the list isn't null? At what point are you advancing anything?
You might find it easier to come up with a recursive diagram if you draw a linked list on a piece of paper and use pencils to act as pointers to the nodes, and walk through your algorithm. Remember, if you're adding to the tail, and if you're not keeping a tail pointer, you have to step through the list to the end. If your assignment is to do this recursively, you'll probably have to create a recursive helper function that takes a Node argument. Either that, or don't create the node first thing -- only create it when you're ready to actually insert it. Otherwise you'd be creating nodes and throwing them away at each recursive call to addToTail.
[add]
Let me go into more detail:
Node curr = head;OK, you're creating a ref to the head. This isn't really necessary if you're working recursively.
curr = curr.next;OK, you're advancing to the child of the head. Again, debatable whether you rally need curr, but whatever.
First question: what happens if it's a one-element list?
What is curr in this case?
curr.next = n;Not good. You're changing the next pointer of the object after the head. Why? This assumes that the list is always two elements long, so it's wrong.
addToTail(val);This doesn't make sense. In recursion, you solve a problem by taking it, simplifying it a bit, and then solving the simplified problem using the same function. But you've changed nothing here -- you're calling addToTail on the object it was called with, and with the same value.
Basically, you have a wrapper class and then a recursive data structure (the linked list itself, built of Nodes). There's just one wrapper per list, so you really can't do recursion on that. You'll probably need to write the recursive functions in the Node class, or in the wrapper class but taking a Node as an argument (thus, a helper function).
Edited by: paulcw on Feb 22, 2010 2:49 AM
Edited by: paulcw on Feb 22, 2010 2:51 AM -
Qt... configure: error
Hi,
When I'm trying to install theme, decorations or program, who's using Qt engine, I'm getting this error:
Qt... configure: error: Qt (>= Qt 3.3 and < 4.0) (headers and libraries) not found. Please check your installation!
I'm using KDE.
ThanksCan you tell me where to add this lines. Here is configure file:
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.61.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
# This configure script is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it.
## M4sh Initialization. ##
# Be more Bourne compatible
DUALCASE=1; export DUALCASE # for MKS sh
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
emulate sh
NULLCMD=:
# Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
# is contrary to our usage. Disable this feature.
alias -g '${1+"$@"}'='"$@"'
setopt NO_GLOB_SUBST
else
case `(set -o) 2>/dev/null` in
*posix*) set -o posix ;;
esac
fi
# PATH needs CR
# Avoid depending upon Character Ranges.
as_cr_letters='abcdefghijklmnopqrstuvwxyz'
as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
as_cr_Letters=$as_cr_letters$as_cr_LETTERS
as_cr_digits='0123456789'
as_cr_alnum=$as_cr_Letters$as_cr_digits
# The user is always right.
if test "${PATH_SEPARATOR+set}" != set; then
echo "#! /bin/sh" >conf$$.sh
echo "exit 0" >>conf$$.sh
chmod +x conf$$.sh
if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
PATH_SEPARATOR=';'
else
PATH_SEPARATOR=:
fi
rm -f conf$$.sh
fi
# Support unset when possible.
if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
as_unset=unset
else
as_unset=false
fi
# IFS
# We need space, tab and new line, in precisely that order. Quoting is
# there to prevent editors from complaining about space-tab.
# (If _AS_PATH_WALK were called with IFS unset, it would disable word
# splitting by setting IFS to empty value.)
as_nl='
IFS=" "" $as_nl"
# Find who we are. Look in the path if we contain no directory separator.
case $0 in
*[\\/]* ) as_myself=$0 ;;
*) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
done
IFS=$as_save_IFS
esac
# We did not find ourselves, most probably we were run as `sh COMMAND'
# in which case we are not to be found in the path.
if test "x$as_myself" = x; then
as_myself=$0
fi
if test ! -f "$as_myself"; then
echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
{ (exit 1); exit 1; }
fi
# Work around bugs in pre-3.0 UWIN ksh.
for as_var in ENV MAIL MAILPATH
do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
done
PS1='$ '
PS2='> '
PS4='+ '
# NLS nuisances.
for as_var in \
LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
LC_TELEPHONE LC_TIME
do
if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
eval $as_var=C; export $as_var
else
($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
fi
done
# Required to use basename.
if expr a : '\(a\)' >/dev/null 2>&1 &&
test "X`expr 00001 : '.*\(...\)'`" = X001; then
as_expr=expr
else
as_expr=false
fi
if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
as_basename=basename
else
as_basename=false
fi
# Name of the executable.
as_me=`$as_basename -- "$0" ||
$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
X"$0" : 'X\(//\)$' \| \
X"$0" : 'X\(/\)' \| . 2>/dev/null ||
echo X/"$0" |
sed '/^.*\/\([^/][^/]*\)\/*$/{
s//\1/
q
/^X\/\(\/\/\)$/{
s//\1/
q
/^X\/\(\/\).*/{
s//\1/
q
s/.*/./; q'`
# CDPATH.
$as_unset CDPATH
if test "x$CONFIG_SHELL" = x; then
if (eval ":") 2>/dev/null; then
as_have_required=yes
else
as_have_required=no
fi
if test $as_have_required = yes && (eval ":
(as_func_return () {
(exit \$1)
as_func_success () {
as_func_return 0
as_func_failure () {
as_func_return 1
as_func_ret_success () {
return 0
as_func_ret_failure () {
return 1
exitcode=0
if as_func_success; then
else
exitcode=1
echo as_func_success failed.
fi
if as_func_failure; then
exitcode=1
echo as_func_failure succeeded.
fi
if as_func_ret_success; then
else
exitcode=1
echo as_func_ret_success failed.
fi
if as_func_ret_failure; then
exitcode=1
echo as_func_ret_failure succeeded.
fi
if ( set x; as_func_ret_success y && test x = \"\$1\" ); then
else
exitcode=1
echo positional parameters were not saved.
fi
test \$exitcode = 0) || { (exit 1); exit 1; }
as_lineno_1=\$LINENO
as_lineno_2=\$LINENO
test \"x\$as_lineno_1\" != \"x\$as_lineno_2\" &&
test \"x\`expr \$as_lineno_1 + 1\`\" = \"x\$as_lineno_2\") || { (exit 1); exit 1; }
") 2> /dev/null; then
else
as_candidate_shells=
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
case $as_dir in
for as_base in sh bash ksh sh5; do
as_candidate_shells="$as_candidate_shells $as_dir/$as_base"
done;;
esac
done
IFS=$as_save_IFS
for as_shell in $as_candidate_shells $SHELL; do
# Try only shells that exist, to save several forks.
if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
{ ("$as_shell") 2> /dev/null <<\_ASEOF
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
emulate sh
NULLCMD=:
# Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
# is contrary to our usage. Disable this feature.
alias -g '${1+"$@"}'='"$@"'
setopt NO_GLOB_SUBST
else
case `(set -o) 2>/dev/null` in
*posix*) set -o posix ;;
esac
fi
_ASEOF
}; then
CONFIG_SHELL=$as_shell
as_have_required=yes
if { "$as_shell" 2> /dev/null <<\_ASEOF
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
emulate sh
NULLCMD=:
# Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
# is contrary to our usage. Disable this feature.
alias -g '${1+"$@"}'='"$@"'
setopt NO_GLOB_SUBST
else
case `(set -o) 2>/dev/null` in
*posix*) set -o posix ;;
esac
fi
(as_func_return () {
(exit $1)
as_func_success () {
as_func_return 0
as_func_failure () {
as_func_return 1
as_func_ret_success () {
return 0
as_func_ret_failure () {
return 1
exitcode=0
if as_func_success; then
else
exitcode=1
echo as_func_success failed.
fi
if as_func_failure; then
exitcode=1
echo as_func_failure succeeded.
fi
if as_func_ret_success; then
else
exitcode=1
echo as_func_ret_success failed.
fi
if as_func_ret_failure; then
exitcode=1
echo as_func_ret_failure succeeded.
fi
if ( set x; as_func_ret_success y && test x = "$1" ); then
else
exitcode=1
echo positional parameters were not saved.
fi
test $exitcode = 0) || { (exit 1); exit 1; }
as_lineno_1=$LINENO
as_lineno_2=$LINENO
test "x$as_lineno_1" != "x$as_lineno_2" &&
test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2") || { (exit 1); exit 1; }
_ASEOF
}; then
break
fi
fi
done
if test "x$CONFIG_SHELL" != x; then
for as_var in BASH_ENV ENV
do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
done
export CONFIG_SHELL
exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
fi
if test $as_have_required = no; then
echo This script requires a shell more modern than all the
echo shells that I found on your system. Please install a
echo modern shell, or manually run the script under such a
echo shell if you do have one.
{ (exit 1); exit 1; }
fi
fi
fi
(eval "as_func_return () {
(exit \$1)
as_func_success () {
as_func_return 0
as_func_failure () {
as_func_return 1
as_func_ret_success () {
return 0
as_func_ret_failure () {
return 1
exitcode=0
if as_func_success; then
else
exitcode=1
echo as_func_success failed.
fi
if as_func_failure; then
exitcode=1
echo as_func_failure succeeded.
fi
if as_func_ret_success; then
else
exitcode=1
echo as_func_ret_success failed.
fi
if as_func_ret_failure; then
exitcode=1
echo as_func_ret_failure succeeded.
fi
if ( set x; as_func_ret_success y && test x = \"\$1\" ); then
else
exitcode=1
echo positional parameters were not saved.
fi
test \$exitcode = 0") || {
echo No shell found that supports shell functions.
echo Please tell [email protected] about your system,
echo including any error possibly output before this
echo message
as_lineno_1=$LINENO
as_lineno_2=$LINENO
test "x$as_lineno_1" != "x$as_lineno_2" &&
test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || {
# Create $as_me.lineno as a copy of $as_myself, but with $LINENO
# uniformly replaced by the line number. The first 'sed' inserts a
# line-number line after each line using $LINENO; the second 'sed'
# does the real work. The second script uses 'N' to pair each
# line-number line with the line containing $LINENO, and appends
# trailing '-' during substitution so that $LINENO is not a special
# case at line end.
# (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
# scripts with optimization help from Paolo Bonzini. Blame Lee
# E. McMahon (1931-1989) for sed's syntax. :-)
sed -n '
p
/[$]LINENO/=
' <$as_myself |
sed '
s/[$]LINENO.*/&-/
t lineno
b
:lineno
N
:loop
s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
t loop
s/-\n.*//
' >$as_me.lineno &&
chmod +x "$as_me.lineno" ||
{ echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
{ (exit 1); exit 1; }; }
# Don't try to exec as it changes $[0], causing all sort of problems
# (the dirname of $[0] is not the place where we might find the
# original and so on. Autoconf is especially sensitive to this).
. "./$as_me.lineno"
# Exit status is that of the last command.
exit
if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
as_dirname=dirname
else
as_dirname=false
fi
ECHO_C= ECHO_N= ECHO_T=
case `echo -n x` in
-n*)
case `echo 'x\c'` in
*c*) ECHO_T=' ';; # ECHO_T is single tab character.
*) ECHO_C='\c';;
esac;;
ECHO_N='-n';;
esac
if expr a : '\(a\)' >/dev/null 2>&1 &&
test "X`expr 00001 : '.*\(...\)'`" = X001; then
as_expr=expr
else
as_expr=false
fi
rm -f conf$$ conf$$.exe conf$$.file
if test -d conf$$.dir; then
rm -f conf$$.dir/conf$$.file
else
rm -f conf$$.dir
mkdir conf$$.dir
fi
echo >conf$$.file
if ln -s conf$$.file conf$$ 2>/dev/null; then
as_ln_s='ln -s'
# ... but there are two gotchas:
# 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
# 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
# In both cases, we have to default to `cp -p'.
ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
as_ln_s='cp -p'
elif ln conf$$.file conf$$ 2>/dev/null; then
as_ln_s=ln
else
as_ln_s='cp -p'
fi
rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
rmdir conf$$.dir 2>/dev/null
if mkdir -p . 2>/dev/null; then
as_mkdir_p=:
else
test -d ./-p && rmdir ./-p
as_mkdir_p=false
fi
if test -x / >/dev/null 2>&1; then
as_test_x='test -x'
else
if ls -dL / >/dev/null 2>&1; then
as_ls_L_option=L
else
as_ls_L_option=
fi
as_test_x='
eval sh -c '\''
if test -d "$1"; then
test -d "$1/.";
else
case $1 in
-*)set "./$1";;
esac;
case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in
???[sx]*):;;*)false;;esac;fi
'\'' sh
fi
as_executable_p=$as_test_x
# Sed expression to map a string onto a valid CPP name.
as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
# Sed expression to map a string onto a valid variable name.
as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
# Check that we are running under the correct shell.
SHELL=${CONFIG_SHELL-/bin/sh}
case X$ECHO in
X*--fallback-echo)
# Remove one level of quotation (which was required for Make).
ECHO=`echo "$ECHO" | sed 's,\\\\\$\\$0,'$0','`
esac
echo=${ECHO-echo}
if test "X$1" = X--no-reexec; then
# Discard the --no-reexec flag, and continue.
shift
elif test "X$1" = X--fallback-echo; then
# Avoid inline document here, it may be left over
elif test "X`($echo '\t') 2>/dev/null`" = 'X\t' ; then
# Yippee, $echo works!
else
# Restart under the correct shell.
exec $SHELL "$0" --no-reexec ${1+"$@"}
fi
if test "X$1" = X--fallback-echo; then
# used as fallback echo
shift
cat <<EOF
$*
EOF
exit 0
fi
# The HP-UX ksh and POSIX shell print the target directory to stdout
# if CDPATH is set.
if test "X${CDPATH+set}" = Xset; then CDPATH=:; export CDPATH; fi
if test -z "$ECHO"; then
if test "X${echo_test_string+set}" != Xset; then
# find a string as large as possible, as long as the shell can cope with it
for cmd in 'sed 50q "$0"' 'sed 20q "$0"' 'sed 10q "$0"' 'sed 2q "$0"' 'echo test'; do
# expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
if (echo_test_string="`eval $cmd`") 2>/dev/null &&
echo_test_string="`eval $cmd`" &&
(test "X$echo_test_string" = "X$echo_test_string") 2>/dev/null
then
break
fi
done
fi
if test "X`($echo '\t') 2>/dev/null`" = 'X\t' &&
echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` &&
test "X$echo_testing_string" = "X$echo_test_string"; then
else
# The Solaris, AIX, and Digital Unix default echo programs unquote
# backslashes. This makes it impossible to quote backslashes using
# echo "$something" | sed 's/\\/\\\\/g'
# So, first we look for a working echo in the user's PATH.
lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
for dir in $PATH /usr/ucb; do
IFS="$lt_save_ifs"
if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
test "X$echo_testing_string" = "X$echo_test_string"; then
echo="$dir/echo"
break
fi
done
IFS="$lt_save_ifs"
if test "X$echo" = Xecho; then
# We didn't find a better echo, so look for alternatives.
if test "X`(print -r '\t') 2>/dev/null`" = 'X\t' &&
echo_testing_string=`(print -r "$echo_test_string") 2>/dev/null` &&
test "X$echo_testing_string" = "X$echo_test_string"; then
# This shell has a builtin print -r that does the trick.
echo='print -r'
elif (test -f /bin/ksh || test -f /bin/ksh$ac_exeext) &&
test "X$CONFIG_SHELL" != X/bin/ksh; then
# If we have ksh, try running configure again with it.
ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
export ORIGINAL_CONFIG_SHELL
CONFIG_SHELL=/bin/ksh
export CONFIG_SHELL
exec $CONFIG_SHELL "$0" --no-reexec ${1+"$@"}
else
# Try using printf.
echo='printf %s\n'
if test "X`($echo '\t') 2>/dev/null`" = 'X\t' &&
echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` &&
test "X$echo_testing_string" = "X$echo_test_string"; then
# Cool, printf works
elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` &&
test "X$echo_testing_string" = 'X\t' &&
echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
test "X$echo_testing_string" = "X$echo_test_string"; then
CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL
export CONFIG_SHELL
SHELL="$CONFIG_SHELL"
export SHELL
echo="$CONFIG_SHELL $0 --fallback-echo"
elif echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` &&
test "X$echo_testing_string" = 'X\t' &&
echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
test "X$echo_testing_string" = "X$echo_test_string"; then
echo="$CONFIG_SHELL $0 --fallback-echo"
else
# maybe with a smaller string...
prev=:
for cmd in 'echo test' 'sed 2q "$0"' 'sed 10q "$0"' 'sed 20q "$0"' 'sed 50q "$0"'; do
if (test "X$echo_test_string" = "X`eval $cmd`") 2>/dev/null
then
break
fi
prev="$cmd"
done
if test "$prev" != 'sed 50q "$0"'; then
echo_test_string=`eval $prev`
export echo_test_string
exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "$0" ${1+"$@"}
else
# Oops. We lost completely, so just stick with echo.
echo=echo
fi
fi
fi
fi
fi
fi
# Copy echo and quote the copy suitably for passing to libtool from
# the Makefile, instead of quoting the original, which is used later.
ECHO=$echo
if test "X$ECHO" = "X$CONFIG_SHELL $0 --fallback-echo"; then
ECHO="$CONFIG_SHELL \\\$\$0 --fallback-echo"
fi
tagnames=${tagnames+${tagnames},}CXX
tagnames=${tagnames+${tagnames},}F77
exec 7<&0 </dev/null 6>&1
# Name of the host.
# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
# so uname gets run too.
ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
# Initializations.
ac_default_prefix=/usr/local
ac_clean_files=
ac_config_libobj_dir=.
LIBOBJS=
cross_compiling=no
subdirs=
MFLAGS=
MAKEFLAGS=
SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package.
PACKAGE_NAME=
PACKAGE_TARNAME=
PACKAGE_VERSION=
PACKAGE_STRING=
PACKAGE_BUGREPORT=
ac_unique_file="acinclude.m4"
ac_default_prefix=${KDEDIR:-the kde prefix}
# Factoring default headers for most tests.
ac_includes_default="\
#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
# include <stdlib.h>
# endif
#endif
#ifdef HAVE_STRING_H
# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
# include <memory.h>
# endif
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif"
ac_subst_vars='SHELL
PATH_SEPARATOR
PACKAGE_NAME
PACKAGE_TARNAME
PACKAGE_VERSION
PACKAGE_STRING
PACKAGE_BUGREPORT
exec_prefix
prefix
program_transform_name
bindir
sbindir
libexecdir
datarootdir
datadir
sysconfdir
sharedstatedir
localstatedir
includedir
oldincludedir
docdir
infodir
htmldir
dvidir
pdfdir
psdir
libdir
localedir
mandir
DEFS
ECHO_C
ECHO_N
ECHO_T
LIBS
build_alias
host_alias
target_alias
build
build_cpu
build_vendor
build_os
host
host_cpu
host_vendor
host_os
target
target_cpu
target_vendor
target_os
INSTALL_PROGRAM
INSTALL_SCRIPT
INSTALL_DATA
CYGPATH_W
PACKAGE
VERSION
ACLOCAL
AUTOCONF
AUTOMAKE
AUTOHEADER
MAKEINFO
AMTAR
install_sh
STRIP
INSTALL_STRIP_PROGRAM
AWK
SET_MAKE
am__leading_dot
KDECONFIG
kde_libs_prefix
kde_libs_htmldir
CONF_FILES
CC
CFLAGS
LDFLAGS
CPPFLAGS
ac_ct_CC
EXEEXT
OBJEXT
DEPDIR
am__include
am__quote
AMDEP_TRUE
AMDEP_FALSE
AMDEPBACKSLASH
CCDEPMODE
am__fastdepCC_TRUE
am__fastdepCC_FALSE
CPP
CXX
CXXFLAGS
ac_ct_CXX
CXXDEPMODE
am__fastdepCXX_TRUE
am__fastdepCXX_FALSE
WOVERLOADED_VIRTUAL
HAVE_GCC_VISIBILITY
unsermake_enable_pch_TRUE
unsermake_enable_pch_FALSE
USE_EXCEPTIONS
USE_RTTI
CXXCPP
NOOPT_CXXFLAGS
NOOPT_CFLAGS
ENABLE_PERMISSIVE_FLAG
LDFLAGS_AS_NEEDED
LDFLAGS_NEW_DTAGS
KDE_USE_FINAL_TRUE
KDE_USE_FINAL_FALSE
KDE_USE_CLOSURE_TRUE
KDE_USE_CLOSURE_FALSE
KDE_NO_UNDEFINED
KDE_USE_NMCHECK_TRUE
KDE_USE_NMCHECK_FALSE
GREP
EGREP
LN_S
ECHO
AR
RANLIB
F77
FFLAGS
ac_ct_F77
LIBTOOL
KDE_PLUGIN
KDE_CHECK_PLUGIN
MSGFMT
GMSGFMT
XGETTEXT
LIBUTIL
LIBCOMPAT
LIBCRYPT
LIBRESOLV
LIB_POLL
FRAMEWORK_COREAUDIO
LIBSOCKET
X_EXTRA_LIBS
LIBUCB
LIBDL
KDE_USE_FPIE
KDE_USE_PIE
include_x11_TRUE
include_x11_FALSE
XMKMF
X_PRE_LIBS
LIB_X11
LIB_XRENDER
LIBSM
X_INCLUDES
X_LDFLAGS
x_includes
x_libraries
QTE_NORTTI
LIB_XEXT
LIBPTHREAD
USE_THREADS
KDE_MT_LDFLAGS
KDE_MT_LIBS
USER_INCLUDES
USER_LDFLAGS
LIBZ
LIBPNG
LIBJPEG
qt_libraries
qt_includes
QT_INCLUDES
QT_LDFLAGS
PERL
MOC
UIC
UIC_TR
LIB_QT
LIB_QPE
kde_qtver
KDE_EXTRA_RPATH
KDE_RPATH
X_RPATH
kde_libraries
kde_includes
KDE_LDFLAGS
KDE_INCLUDES
all_includes
all_libraries
AUTODIRS
include_ARTS_TRUE
include_ARTS_FALSE
MAKEKDEWIDGETS
KCONFIG_COMPILER
KCFG_DEPENDENCIES
DCOPIDLNG
DCOPIDL
DCOPIDL2CPP
DCOP_DEPENDENCIES
MCOPIDL
ARTSCCONFIG
MEINPROC
KDE_XSL_STYLESHEET
XMLLINT
kde_htmldir
kde_appsdir
kde_icondir
kde_sounddir
kde_datadir
kde_locale
kde_confdir
kde_kcfgdir
kde_mimedir
kde_wallpaperdir
kde_bindir
xdg_appsdir
xdg_menudir
xdg_directorydir
kde_templatesdir
kde_servicesdir
kde_servicetypesdir
kde_moduledir
kdeinitdir
kde_styledir
kde_widgetdir
LIB_KDED
LIB_KDECORE
LIB_KDEUI
LIB_KIO
LIB_KJS
LIB_SMB
LIB_KAB
LIB_KABC
LIB_KHTML
LIB_KSPELL
LIB_KPARTS
LIB_KDEPRINT
LIB_KUTILS
LIB_KDEPIM
LIB_KIMPROXY
LIB_KNEWSTUFF
LIB_KDNSSD
LIB_KUNITTEST
LIB_KSYCOCA
LIB_KFILE
LIB_KFM
TOPSUBDIRS
LIBOBJS
LTLIBOBJS'
ac_subst_files=''
ac_precious_vars='build_alias
host_alias
target_alias
CC
CFLAGS
LDFLAGS
LIBS
CPPFLAGS
CPP
CXX
CXXFLAGS
CCC
CXXCPP
F77
FFLAGS
XMKMF'
# Initialize some variables set by options.
ac_init_help=
ac_init_version=false
# The variables have the same names as the options, with
# dashes changed to underlines.
cache_file=/dev/null
exec_prefix=NONE
no_create=
no_recursion=
prefix=NONE
program_prefix=NONE
program_suffix=NONE
program_transform_name=s,x,x,
silent=
site=
srcdir=
verbose=
x_includes=NONE
x_libraries=NONE
# Installation directory options.
# These are left unexpanded so users can "make install exec_prefix=/foo"
# and all the variables that are supposed to be based on exec_prefix
# by default will actually change.
# Use braces instead of parens because sh, perl, etc. also accept them.
# (The list follows the same order as the GNU Coding Standards.)
bindir='${exec_prefix}/bin'
sbindir='${exec_prefix}/sbin'
libexecdir='${exec_prefix}/libexec'
datarootdir='${prefix}/share'
datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE}'
infodir='${datarootdir}/info'
htmldir='${docdir}'
dvidir='${docdir}'
pdfdir='${docdir}'
psdir='${docdir}'
libdir='${exec_prefix}/lib'
localedir='${datarootdir}/locale'
mandir='${datarootdir}/man'
ac_prev=
ac_dashdash=
for ac_option
do
# If the previous option needs an argument, assign it.
if test -n "$ac_prev"; then
eval $ac_prev=\$ac_option
ac_prev=
continue
fi
case $ac_option in
*=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
*) ac_optarg=yes ;;
esac
# Accept the important Cygnus configure options, so we can diagnose typos.
case $ac_dashdash$ac_option in
ac_dashdash=yes ;;
-bindir | --bindir | --bindi | --bind | --bin | --bi)
ac_prev=bindir ;;
-bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
bindir=$ac_optarg ;;
-build | --build | --buil | --bui | --bu)
ac_prev=build_alias ;;
-build=* | --build=* | --buil=* | --bui=* | --bu=*)
build_alias=$ac_optarg ;;
-cache-file | --cache-file | --cache-fil | --cache-fi \
| --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
ac_prev=cache_file ;;
-cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
| --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
cache_file=$ac_optarg ;;
--config-cache | -C)
cache_file=config.cache ;;
-datadir | --datadir | --datadi | --datad)
ac_prev=datadir ;;
-datadir=* | --datadir=* | --datadi=* | --datad=*)
datadir=$ac_optarg ;;
-datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \
| --dataroo | --dataro | --datar)
ac_prev=datarootdir ;;
-datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \
| --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
datarootdir=$ac_optarg ;;
-disable-* | --disable-*)
ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
# Reject names that are not valid shell variable names.
expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null &&
{ echo "$as_me: error: invalid feature name: $ac_feature" >&2
{ (exit 1); exit 1; }; }
ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'`
eval enable_$ac_feature=no ;;
-docdir | --docdir | --docdi | --doc | --do)
ac_prev=docdir ;;
-docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)
docdir=$ac_optarg ;;
-dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
ac_prev=dvidir ;;
-dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
dvidir=$ac_optarg ;;
-enable-* | --enable-*)
ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
# Reject names that are not valid shell variable names.
expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null &&
{ echo "$as_me: error: invalid feature name: $ac_feature" >&2
{ (exit 1); exit 1; }; }
ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'`
eval enable_$ac_feature=\$ac_optarg ;;
-exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
| --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
| --exec | --exe | --ex)
ac_prev=exec_prefix ;;
-exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
| --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
| --exec=* | --exe=* | --ex=*)
exec_prefix=$ac_optarg ;;
-gas | --gas | --ga | --g)
# Obsolete; use --with-gas.
with_gas=yes ;;
-help | --help | --hel | --he | -h)
ac_init_help=long ;;
-help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
ac_init_help=recursive ;;
-help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
ac_init_help=short ;;
-host | --host | --hos | --ho)
ac_prev=host_alias ;;
-host=* | --host=* | --hos=* | --ho=*)
host_alias=$ac_optarg ;;
-htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)
ac_prev=htmldir ;;
-htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \
| --ht=*)
htmldir=$ac_optarg ;;
-includedir | --includedir | --includedi | --included | --include \
| --includ | --inclu | --incl | --inc)
ac_prev=includedir ;;
-includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
| --includ=* | --inclu=* | --incl=* | --inc=*)
includedir=$ac_optarg ;;
-infodir | --infodir | --infodi | --infod | --info | --inf)
ac_prev=infodir ;;
-infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
infodir=$ac_optarg ;;
-libdir | --libdir | --libdi | --libd)
ac_prev=libdir ;;
-libdir=* | --libdir=* | --libdi=* | --libd=*)
libdir=$ac_optarg ;;
-libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
| --libexe | --libex | --libe)
ac_prev=libexecdir ;;
-libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
| --libexe=* | --libex=* | --libe=*)
libexecdir=$ac_optarg ;;
-localedir | --localedir | --localedi | --localed | --locale)
ac_prev=localedir ;;
-localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)
localedir=$ac_optarg ;;
-localstatedir | --localstatedir | --localstatedi | --localstated \
| --localstate | --localstat | --localsta | --localst | --locals)
ac_prev=localstatedir ;;
-localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
| --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)
localstatedir=$ac_optarg ;;
-mandir | --mandir | --mandi | --mand | --man | --ma | --m)
ac_prev=mandir ;;
-mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
mandir=$ac_optarg ;;
-nfp | --nfp | --nf)
# Obsolete; use --without-fp.
with_fp=no ;;
-no-create | --no-create | --no-creat | --no-crea | --no-cre \
| --no-cr | --no-c | -n)
no_create=yes ;;
-no-recursion | --no-recursion | --no-recursio | --no-recursi \
| --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
no_recursion=yes ;;
-oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
| --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
| --oldin | --oldi | --old | --ol | --o)
ac_prev=oldincludedir ;;
-oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
| --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
| --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
oldincludedir=$ac_optarg ;;
-prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
ac_prev=prefix ;;
-prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
prefix=$ac_optarg ;;
-program-prefix | --program-prefix | --program-prefi | --program-pref \
| --program-pre | --program-pr | --program-p)
ac_prev=program_prefix ;;
-program-prefix=* | --program-prefix=* | --program-prefi=* \
| --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
program_prefix=$ac_optarg ;;
-program-suffix | --program-suffix | --program-suffi | --program-suff \
| --program-suf | --program-su | --program-s)
ac_prev=program_suffix ;;
-program-suffix=* | --program-suffix=* | --program-suffi=* \
| --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
program_suffix=$ac_optarg ;;
-program-transform-name | --program-transform-name \
| --program-transform-nam | --program-transform-na \
| --program-transform-n | --program-transform- \
| --program-transform | --program-transfor \
| --program-transfo | --program-transf \
| --program-trans | --program-tran \
| --progr-tra | --program-tr | --program-t)
ac_prev=program_transform_name ;;
-program-transform-name=* | --program-transform-name=* \
| --program-transform-nam=* | --program-transform-na=* \
| --program-transform-n=* | --program-transform-=* \
| --program-transform=* | --program-transfor=* \
| --program-transfo=* | --program-transf=* \
| --program-trans=* | --program-tran=* \
| --progr-tra=* | --program-tr=* | --program-t=*)
program_transform_name=$ac_optarg ;;
-pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)
ac_prev=pdfdir ;;
-pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)
pdfdir=$ac_optarg ;;
-psdir | --psdir | --psdi | --psd | --ps)
ac_prev=psdir ;;
-psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
psdir=$ac_optarg ;;
-q | -quiet | --quiet | --quie | --qui | --qu | --q \
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
| --sbi=* | --sb=*)
sbindir=$ac_optarg ;;
-sharedstatedir | --sharedstatedir | --sharedstatedi \
| --sharedstated | --sharedstate | --sharedstat | --sharedsta \
| --sharedst | --shareds | --shared | --share | --shar \
| --sha | --sh)
ac_prev=sharedstatedir ;;
-sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
| --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
| --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
| --sha=* | --sh=*)
sharedstatedir=$ac_optarg ;;
-site | --site | --sit)
ac_prev=site ;;
-site=* | --site=* | --sit=*)
site=$ac_optarg ;;
-srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
ac_prev=srcdir ;;
-srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
srcdir=$ac_optarg ;;
-sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
| --syscon | --sysco | --sysc | --sys | --sy)
ac_prev=sysconfdir ;;
-sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
| --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
sysconfdir=$ac_optarg ;;
-target | --target | --targe | --targ | --tar | --ta | --t)
ac_prev=target_alias ;;
-target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
target_alias=$ac_optarg ;;
-v | -verbose | --verbose | --verbos | --verbo | --verb)
verbose=yes ;;
-version | --version | --versio | --versi | --vers | -V)
ac_init_version=: ;;
-with-* | --with-*)
ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
# Reject names that are not valid shell variable names.
expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null &&
{ echo "$as_me: error: invalid package name: $ac_package" >&2
{ (exit 1); exit 1; }; }
ac_package=`echo $ac_package | sed 's/[-.]/_/g'`
eval with_$ac_package=\$ac_optarg ;;
-without-* | --without-*)
ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'`
# Reject names that are not valid shell variable names.
expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null &&
{ echo "$as_me: error: invalid package name: $ac_package" >&2
{ (exit 1); exit 1; }; }
ac_package=`echo $ac_package | sed 's/[-.]/_/g'`
eval with_$ac_package=no ;;
--x)
# Obsolete; use --with-x.
with_x=yes ;;
-x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
| --x-incl | --x-inc | --x-in | --x-i)
ac_prev=x_includes ;;
-x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
| --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
x_includes=$ac_optarg ;;
-x-libraries | --x-libraries | --x-librarie | --x-librari \
| --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
ac_prev=x_libraries ;;
-x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
| --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
x_libraries=$ac_optarg ;;
-*) { echo "$as_me: error: unrecognized option: $ac_option
Try \`$0 --help' for more information." >&2
{ (exit 1); exit 1; }; }
*=*)
ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
# Reject names that are not valid shell variable names.
expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
{ echo "$as_me: error: invalid variable name: $ac_envvar" >&2
{ (exit 1); exit 1; }; }
eval $ac_envvar=\$ac_optarg
export $ac_envvar ;;
# FIXME: should be removed in autoconf 3.0.
echo "$as_me: WARNING: you should use --build, --host, --target" >&2
expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
echo "$as_me: WARNING: invalid host type: $ac_option" >&2
: ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
esac
done
if test -n "$ac_prev"; then
ac_option=--`echo $ac_prev | sed 's/_/-/g'`
{ echo "$as_me: error: missing argument to $ac_option" >&2
{ (exit 1); exit 1; }; }
fi
# Be sure to have absolute directory names.
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
libdir localedir mandir
do
eval ac_val=\$$ac_var
case $ac_val in
[\\/$]* | ?:[\\/]* ) continue;;
NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
esac
{ echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
{ (exit 1); exit 1; }; }
done
# There might be people who depend on the old broken behavior: `$host'
# used to hold the argument of --host etc.
# FIXME: To remove some day.
build=$build_alias
host=$host_alias
target=$target_alias
# FIXME: To remove some day.
if test "x$host_alias" != x; then
if test "x$build_alias" = x; then
cross_compiling=maybe
echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be used." >&2
elif test "x$build_alias" != "x$host_alias"; then
cross_compiling=yes
fi
fi
ac_tool_prefix=
test -n "$host_alias" && ac_tool_prefix=$host_alias-
test "$silent" = yes && exec 6>/dev/null
ac_pwd=`pwd` && test -n "$ac_pwd" &&
ac_ls_di=`ls -di .` &&
ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
{ echo "$as_me: error: Working directory cannot be determined" >&2
{ (exit 1); exit 1; }; }
test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
{ echo "$as_me: error: pwd does not report name of working directory" >&2
{ (exit 1); exit 1; }; }
# Find the source files, if location was not specified.
if test -z "$srcdir"; then
ac_srcdir_defaulted=yes
# Try the directory containing this script, then the parent directory.
ac_confdir=`$as_dirname -- "$0" ||
$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
X"$0" : 'X\(//\)[^/]' \| \
X"$0" : 'X\(//\)$' \| \
X"$0" : 'X\(/\)' \| . 2>/dev/null ||
echo X"$0" |
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
s//\1/
q
/^X\(\/\/\)[^/].*/{
s//\1/
q
/^X\(\/\/\)$/{
s//\1/
q
/^X\(\/\).*/{
s//\1/
q
s/.*/./; q'`
srcdir=$ac_confdir
if test ! -r "$srcdir/$ac_unique_file"; then
srcdir=..
fi
else
ac_srcdir_defaulted=no
fi
if test ! -r "$srcdir/$ac_unique_file"; then
test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
{ echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2
{ (exit 1); exit 1; }; }
fi
ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
ac_abs_confdir=`(
cd "$srcdir" && test -r "./$ac_unique_file" || { echo "$as_me: error: $ac_msg" >&2
{ (exit 1); exit 1; }; }
pwd)`
# When building in place, set srcdir=.
if test "$ac_abs_confdir" = "$ac_pwd"; then
srcdir=.
fi
# Remove unnecessary trailing slashes from srcdir.
# Double slashes in file names in object file debugging info
# mess up M-x gdb in Emacs.
case $srcdir in
*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;;
esac
for ac_var in $ac_precious_vars; do
eval ac_env_${ac_var}_set=\${${ac_var}+set}
eval ac_env_${ac_var}_value=\$${ac_var}
eval ac_cv_env_${ac_var}_set=\${${ac_var}+set}
eval ac_cv_env_${ac_var}_value=\$${ac_var}
done
# Report the --help message.
if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures this package to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print \`checking...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for \`--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or \`..']
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[$ac_default_prefix]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, \`make install' will install all the files in
\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify
an installation prefix other than \`$ac_default_prefix' using \`--prefix',
for instance \`--prefix=\$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]
_ACEOF
cat <<\_ACEOF
Program names:
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
--program-transform-name=PROGRAM run sed PROGRAM on installed program names
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]
--target=TARGET configure for building compilers for TARGET [HOST]
_ACEOF
fi
if test -n "$ac_init_help"; then
cat <<\_ACEOF
Optional Features:
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--disable-fast-perl disable fast Makefile generation (needs perl)
--enable-debug=ARG enables debug symbols (yes|no|full) default=no
--disable-debug disables debug output and debug symbols default=no
--enable-strict compiles with strict compiler options (may not
work!)
--disable-warnings disables compilation with -Wall and similar
--enable-profile creates profiling infos default=no
--disable-dependency-tracking Speeds up one-time builds
--enable-dependency-tracking Do not reject slow dependency extractors
--enable-pch enables precompiled header support (currently only
KCC or gcc >=3.4+unsermake) default=no
--enable-coverage use gcc coverage testing
--enable-new-ldflags enable the new linker flags
--enable-final build size optimized apps (experimental - needs lots
of memory)
--enable-closure delay template instantiation
--enable-nmcheck enable automatic namespace cleanness check
--enable-shared[=PKGS] build shared libraries [default=yes]
--enable-static[=PKGS] build static libraries [default=no]
--enable-libsuffix /lib directory suffix (64,32,none,auto=default)
--enable-fast-install[=PKGS]
optimize for fast installation [default=yes]
--disable-libtool-lock avoid locking (might break parallel builds)
--enable-pie platform supports PIE linking default=detect
--enable-embedded link to Qt-embedded, don't use X
--enable-qtopia link to Qt-embedded, link to the Qtopia Environment
--enable-mac link to Qt/Mac (don't use X)
--disable-mt link to non-threaded Qt (deprecated)
--disable-threading disables threading even if libpthread found
--disable-rpath do not use the rpath feature of ld
--disable-path-check don't try to find out, where to install
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
--with-pic try to use only PIC/non-PIC objects [default=use
both]
--with-tags[=TAGS] include additional configurations [automatic]
--with-extra-includes=DIR
adds non standard include paths
--with-extra-libs=DIR adds non standard library paths
--with-qt-dir=DIR where the root of Qt is installed
--with-qt-includes=DIR where the Qt includes are.
--with-qt-libraries=DIR where the Qt library is installed.
--without-arts build without aRts default=no
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CPP C preprocessor
CXX C++ compiler command
CXXFLAGS C++ compiler flags
CXXCPP C++ preprocessor
F77 Fortran 77 compiler command
FFLAGS Fortran 77 compiler flags
XMKMF Path to xmkmf, Makefile generator for X Window System
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
_ACEOF
ac_status=$?
fi
if test "$ac_init_help" = "recursive"; then
# If there are subdirs, report their specific --help.
for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
test -d "$ac_dir" || continue
ac_builddir=.
case "$ac_dir" in
.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
# A ".." for each directory in $ac_dir_suffix.
ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'`
case $ac_top_builddir_sub in
"") ac_top_builddir_sub=. ac_top_build_prefix= ;;
*) ac_top_build_prefix=$ac_top_builddir_sub/ ;;
esac ;;
esac
ac_abs_top_builddir=$ac_pwd
ac_abs_builddir=$ac_pwd$ac_dir_suffix
# for backward compatibility:
ac_top_builddir=$ac_top_build_prefix
case $srcdir in
.) # We are building in place.
ac_srcdir=.
ac_top_srcdir=$ac_top_builddir_sub
ac_abs_top_srcdir=$ac_pwd ;;
[\\/]* | ?:[\\/]* ) # Absolute name.
ac_srcdir=$srcdir$ac_dir_suffix;
ac_top_srcdir=$srcdir
ac_abs_top_srcdir=$srcdir ;;
*) # Relative name.
ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
ac_top_srcdir=$ac_top_build_prefix$srcdir
ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
esac
ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
cd "$ac_dir" || { ac_status=$?; continue; }
# Check for guested configure.
if test -f "$ac_srcdir/configure.gnu"; then
echo &&
$SHELL "$ac_srcdir/configure.gnu" --help=recursive
elif test -f "$ac_srcdir/configure"; then
echo &&
$SHELL "$ac_srcdir/configure" --help=recursive
else
echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
fi || ac_status=$?
cd "$ac_pwd" || { ac_status=$?; break; }
done
fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
configure
generated by GNU Autoconf 2.61
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.
_ACEOF
exit
fi
cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by $as_me, which was
generated by GNU Autoconf 2.61. Invocation command line was
$ $0 $@
_ACEOF
exec 5>>config.log
cat <<_ASUNAME
## Platform. ##
hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
uname -m = `(uname -m) 2>/dev/null || echo unknown`
uname -r = `(uname -r) 2>/dev/null || echo unknown`
uname -s = `(uname -s) 2>/dev/null || echo unknown`
uname -v = `(uname -v) 2>/dev/null || echo unknown`
/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown`
/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown`
/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown`
/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown`
/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown`
/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown`
/bin/universe = `(/bin/universe) 2>/dev/null | -
Help with recursive function to print number patterns
I'm sorry for having to ask for homework help - I'm badly stuck on this! Can someone give me a kick in the right direction with this?
need a recursive function with a single positive int parameter n. the function should write (2^n - 1) integers and should be in the following pattern...
n = 1, Output: 1
n = 2, Output: 1 2 1
n = 3, Output: 1 2 1 3 1 2 1
n = 4, Output: 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
n = 5, Output: 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
function should valid for all positive integer values of n
This was tagged as a 'short' problem...so it shouldnt take too much code...I am hung on on the following:
*Do I keep track of the numbers printed, if so how? I only have a single parameter to call with so I am confused as to how I could get an entire pattern without keeping track of the history
*I had initially thought it would be necessary to cut it in half and do the 2nd half backwards (ie: for n=3, I would take care of the 1 2 1 - then 3 - then 1 2 1...but even then it seems like I could cut 1 2 1 in half the same way and therefor I should be able to do ALL of it in single parts...
Can someone veer me in the right direction here? I'm really lost with this.This was tagged as a 'short' problem...so it shouldnt
take too much code...Yeah, the method body could be done in a few lines.
I am hung on on the following:
*Do I keep track of the numbers printed, if so how?Not explicitly. Use the call stack. That is, use the fact that when you're recursing, the previous values of numbers are preserved in the previous method invocation.
I only have a single parameter to call with so I am
confused as to how I could get an entire pattern
without keeping track of the historyYou don't have to store anything across method invocations.
I had initially thought it would be necessary to cut
it in half and do the 2nd half backwards (ie: for
n=3, I would take care of the 1 2 1 - then 3 - then 1
2 1...but even then it seems like I could cut 1 2 1
in half the same way and therefor I should be able to
do ALL of it in single parts...No, it's MUCH simpler than that. It's easier than yo uthink.
Can someone veer me in the right direction here? I'm
really lost with this.Try this simpler version of the problem:
Write a recursive method that creates this output:
n = 1: 1
n = 2: 1 2
n = 3: 1 2 3
And try this simpler version:
n = 1: 1
n = 2: 2 1
n = 3: 3 2 1 -
Need a little help with recursion
i don't follow this recursion demo very well. After 5 is passed to the n parameter of factR(), could anyone give me an explanation of how it works?
Thanks.
class Factorial {
int factR(int n) {
int result;
if(n == 1) return 1;
result = factR(n-1)*n;
System.out.println("result "+result); //2,6,24,120
return result;
class RecursionDemo {
public static void main(String[] args) {
Factorial f = new Factorial();
System.out.println("Factorial of 5 is "+f.factR(5));
}result 2
result 6
result 24
result 120
Factorial of 5 is 120i've having problems following mostly the second part of this code's output
when n equals 1, can anyone tell me where 1 is returned to? I'm also not sure how "result" at first equals 2, then 6 etc. and what makes n increase from to 2 to 5?
can anyone help?
class Factorial {
int factR(int n) {
int result;
if(n == 1) return 1;
System.out.println("n = "+n);
result = factR(n-1)*n;
System.out.println("result = "+result); //2,6,24,120
System.out.println("n = "+n);
return result;
class RecursionDemo {
public static void main(String[] args) {
Factorial f = new Factorial();
System.out.println("Factorial of 5 is "+f.factR(5));
}n = 5
n = 4
n = 3
n = 2
result = 2
n = 2
result = 6
n = 3
result = 24
n = 4
result = 120
n = 5
Factorial of 5 is 120 -
Please help convering recursion to iteration
Hello all, I am relatively new with Java. I am implementing a Region Growing algorithm, and it works fine for small regions. For large regions, I get the usual stack overflow problem. I was never able to increase my stack size and didn't really want that approach. I have posted the method that does the region growing. It is messy, and I know there is stuff in there that will not make sense but, the region growing section is there. I have given up and need some help...
Thanks everyone who can help!!
private void growRegion(int x, int y) {
double red = 0;
double green = 0;
double blue = 0;
double alpha = 0;
pixelArray2 = new double[5];
wraster.getPixel(x,y,pixelArray2);
red = pixelArray2[0];
green = pixelArray2[1];
blue = pixelArray2[2];
alpha = pixelArray2[3];
pixelChange2[0] = 195;
pixelChange2[1] = 195;
pixelChange2[2] = 195;
pixelChange2[3] = alpha;
if (x < 0 || y < 0) return;
if (x >= wraster.getWidth()) return;
if (y >= wraster.getHeight()) return;
// the pixel has been assigned a threshold but has not been associated
// with a region.
if (assigned[x][y]==true && associated[x][y]==false){
wraster.setPixel(x,y,pixelChange2);
associated[x][y] = true;
// the recursive calls that are driving me nuts
growRegion(x+1,y);
growRegion(x-1,y);
growRegion(x,y+1);
growRegion(x,y-1);
}else{
// do something else...anything but recursion
}You should use some recursion but this looks like an over-use. Method growRegion starts (after some initializations) with a termination statement,
if (x < 0 || y < 0) return;
if (x >= wraster.getWidth()) return;
if (y >= wraster.getHeight()) return; This means you could probably remove this and instead use for-loops to drive the recursion,
if (d != 0)
for (int i=x+1, l=wraster.getWidth(); i<l; i++)
growRegion(i,y,0);
if (d != 1)
for (int i=x-1; i>=0; i--)
growRegion(i,y,1);
if (d != 2)
for (int i=y+1, l=wraster.getHeight(); i<l; i++)
growRegion(x,i,2);
if (d != 3)
for (int i=y-1; i>=0; i--)
growRegion(x,i,3); The signature of growRegion is now,
growRegion(int x, int y, int d)And in the very first call d (direction) must be -1. I think this will replace lots of (unnecessary) recursion with iteration but I'm not sure. It an easy change so it could be worth a try -:) -
Help!! recursive function call
* The function which build the category tree
public String categoryTree(Statement stat, boolean isMore, int id) {
if(!isMore) {
return "";
else
String sql = " select t_category_relation.category_relation_id, t_category_relation.level_in, " +
" t_category_item.category_item_id, t_category_item.category_name_jpn_NV from " +
" t_category_item, t_category_relation " +
" where " +
" t_category_item.category_item_id = t_category_relation.category_item_id and " +
" t_category_relation.parent_id = " + id + " and t_category_relation.parent_id<>0";
// return sql;
try{
ResultSet res = stat.executeQuery(sql);
String spacer = "";
String input = "";
while(res.next()) {
int level = res.getInt(2);
id = res.getInt(1);
for(int i = 0; i < level; i ++) {
spacer +=" ";
input ="+ id: " +id + " NAME " + res.getString(4) + "\n</td>\n<td align=center>\n<input type=checkbox value=" +String.valueOf(id) + " name=categoryid>\n</td>\n</tr>\n";
return "\t\t<TR>\n\t\t\t<TD>" + spacer + input + categoryTree(stat, true, id);
if(spacer.equals("")){
return input+categoryTree(stat, false, id);
}catch(SQLException e) {
return "SQL Exception";
return categoryTree(stat, false, id);
}I am writing a menu generated base on a tree like relation ship that is store in a database. assume
vegetable has two child and one of the child has another child and so forth.
But I am getting a result like this:
vegetable-->
<1>childe
<1.1>childe
but missing <2>child
because the while loop doesn't continous looping after the 1.1.
please help me out
thanx in advance>
Re: help!! recursive function call
Author: DrClap Aug 3, 2001 1:15 PM
When you call the method recursively, the second call makes a second query to the database, before you have finished using the ResultSet from the first query. Since you are using the same Statement, executing the second query causes the first query to, um, disappear.
The API documentation for java.sql.Statement says this: "Only one ResultSet object per Statement object can be open at any point in time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All statement execute methods implicitly close a statment's current ResultSet object if an open one exists."
thanx for your reply!
public String categoryTree(int id) {
String sql = " select t_category_relation.category_relation_id, t_category_relation.level_in, " +
" t_category_item.category_item_id, t_category_item.category_name_jpn_NV from " +
" t_category_item, t_category_relation " +
" where " +
" t_category_item.category_item_id = t_category_relation.category_item_id and " +
" t_category_relation.parent_id = " + id;
try{
Connection con = DataSourceUtil.getConnection("name");
Statement stat = con.createStatement();
ResultSet res = stat.executeQuery(sql);
String spacer = "";
String row = "";
while(res.next()) {
int level = res.getInt(2);
id = res.getInt(1);
for(int i = 0; i < level; i++) {
spacer +=" ";
row = " \t\t<tr>\n " +
" \t\t\t<td colspan='2'>" + spacer + " <a href=inventory_edit_product.jsp?categoryid=" + id +">" + res.getString(4) + "</a></td>\n" +
" \t\t</tr>\n ";
return (row + categoryTree(id));
con.close();
}catch(SQLException e) {
return "<tr><td colspan=2>SQL Exception</td></tr>";
return "";
}New I think every recursive call will have it's own statement and resultSet but I am still getting same problem. The while loop stopped when calls reached first base case. Does anybody know why. I expect, assume that while loop will go next when a call reaches the base case which will return "".
Thanx for help -
Please Help - Permutations using recursion..
Please some body help me in generating permutaions using recursion..exact guidelines are as follows..
Producing consecutive permutations.Need to develop a method that lists one by one all permutations of the numbers 1, 2, �, n (n is a positive integer).
(a) Recursive method . Given a verbal description of the algorithm listing all permutations one by one, you are supposed to develop a recursive method with the following header:
public static boolean nextPermutation(int[] array)The method receives an integer array parameter which is a permutation of integers 1, 2, �, n. If there is �next� permutation to the permutation represented by the array, then the method returns true and the array is changed so that it represents the �next� permutation. If there is no �next� permutation, the method returns false and does not change the array.
Here is a verbal description of the recursive algorithm you need to implement:
1. The first permutation is the permutation represented by the sequence (1, 2, �, n).
2. The last permutation is the permutation represented by the sequence (n, �, 2, 1).
3. If n a ,...,a 1 is an arbitrary permutation, then the �next� permutation is produced by
the following procedure:
(i) If the maximal element of the array (which is n) is not in the first position of the array, say i n = a , where i > 1, then just swap i a and i-1 a . This will give you the �next� permutation in this case.
(ii) If the maximal element of the array is in the first position, so 1 n = a , then to find
the �next� permutation to the permutation ( ,..., ) 1 n a a , first find the �next�
permutation to ( ,..., ) 2 n a a , and then add 1 a to the end of thus obtained array of (n-1) elements.
(iii) Consecutively applying this algorithm to permutations starting from (1, 2, �, n),you will eventually list all n! possible permutations. The last one will be (n, �, 2, 1).For example, below is the sequence of permutations for n = 3 .
Please help...i have trying this for long time
plesae help...i apreciate your time..and help..thank youpublic class Permu {
public static boolean nextPermutation(int a[]) {
return(permute(a, 0));
public static boolean permute(int v[], int start) {
int n = v.length;
if (start == (n - 1)) { //if its the end of the sequence genereated then print them
count++;
//print(v,n);
return false;
} else {
for (int i = start; i < n; i++) { //swap the start element with the ith element to get n first sequeces
int temp = v[start];
v[start] = v;
v[i] = temp;
permute(v, start + 1);
//of the n the first is kept constant the same is applied for the rest sequence
//int tmp = v[i];
v[i] = v[start];
v[start] = temp;
return true;
public static void main(String[] args) {
int v[] = {1, 2};//this is the array which should contain the items to be permuted
do{
for(int i=0;i<2;i++)
System.out.print(v[i]);
System.out.println();
}while(nextPermutation(v));
[i]Output:
123
123
123
123
123
This is exact code i am trying to run...pls someone help me out... -
Help needed with recursion algorithm..
I can't seems to figure out which recursion method to use, if anyone can give me some advice, pls do..
Input: There is a row of n elecments with the initial value of 1.
Output: Change all the 1s to 0s using the following conditions.
-The first element can change from 1 to 0, and 0 to 1 at any time (without conditions).
-While the rest of the elements can only be changed to 0 when the preceeding element is 1 and all other elements are 0.
For example, when n = 3
1 1 1 - initial state of all elements
0 1 1 - change first element to 0 w/o condition
0 1 0 - change third element to 0 as only second element is 1 and rest are 0
1 1 0 - change first element to 1 w/0 condition
1 0 0 - change second element to 0 as only first element is 1 and rest are 0
0 0 0 - change first element to 0 w/o condition
I really can't think of a recursive method to work this out, and am desperate to know the answer. Can anyone please help?Sorry about it, you can change the rest of the bit back to 1 but provided that the preceeding bit is also 1.
and that makes the question:
Input: There is a row of n elecments with the initial value of 1.
Output: Change all the 1s to 0s using the following conditions.
-The first element can change from 1 to 0, and 0 to 1 at any time (without conditions).
-While the rest of the elements can only be changed to 0 or 1 when the preceeding element is 1 and all other elements are 0.
For example, when n = 3
1 1 1 - initial state of all elements
0 1 1 - change first element to 0 w/o condition
0 1 0 - change third element to 0 as only second element is 1 and rest are 0
1 1 0 - change first element to 1 w/0 condition
1 0 0 - change second element to 0 as only first element is 1 and rest are 0
0 0 0 - change first element to 0 w/o condition
I'll check my the person who sets the question and get back to you guys as soon as possible. Thanks a lot for helping me out.
Maybe you are looking for
-
Refer to Tabular Form field in Condition of Dynamic Action
I tried to filter on this topic but didn't come up with anything. Is there a way to refer to a field in a tabular form as a condition of a dynamic action? For example, I want to pop up a message (javascript 'alert') when the value of one field in a t
-
Solution!!! (for iTunes not recognizing Nano)
I've written this as a reply to the thread below as well - but as it seems more than just our friend below has this problem I've also posted this as a separate post Hi everybody, I have - like many of you, suffered through this frustrating process of
-
SUM table on different database
I have the same table in two different bases. In one of them should make a view that will make the sum of these two tables. I have created database link and can make queries with one base to another. What do you do?
-
Phone heat up after plug out from charger
Everyday, i will plug in my phone to charge it overnight. One thing i noticed for a few days is, once i plug out my phone in the morning, the phone starts to get very hot, and battery start to drain. Sometimes it cools down itself, sometime you need
-
Can we have Approval Process at Opporunity Level?-
Hi, Can we have Approval Process at Opportunity level instead of at Quote Level?If so,Please help me on this. Thanks in advance. Regards Raju