Combining recursive tree traversal subroutine and calling method?
I wrote the following bit to take a TreeMap of string (words) and build into one long inorder traversed string (alphabetical order). Works fine-this isn't a do my homework problem =).
But I have two questions:
1. How, if any, is it possible to combine the recursive function and the one that calls it into one consolidated subroutine.
2. A little off topic, but can objects of different primitive types (like an int 2D array and a string) be stored with in each node? How can I specify which one is the "key" on traversal (the word), how can i access the other data (array)?
I'm bout to go over some documentation myself, I know I'll find something, but just wanted to know the general consensus on this type of execution. Thanks.
public String toString() {
inOrderTreeResult = "Result of this tree is: ";
inOrderTreeResult += (buildString(root));
return inOrderTreeResult;
public String buildString(TreeNode node){
if (node != null) {
buildString( node.left );
inOrderTreeResult += (node.item + "\n");
buildString( node.right );
return inOrderTreeResult;
}
I'm not so sure I understand. Lemme show some code and explain. I have a simple treemap implementation to create an alphabetical index of words that appear in a text file. Currently the one data in each node is the String word. I want to be able to include the line number and number of iterations on each line that it appears. I could do it sloppily by putting all that information into one string and parsing it out later, or I thought maybe I could somehow add a 2D array (actually a vector for expandability) that I can access later when i print out the index.
Here's the constructor class of the Tree:
static class TreeNode {
String item;
TreeNode left;
TreeNode right;
TreeNode(String str) {
item = str;
} On insertion, it traverses for the proper position on the tree and should add the string, if it exists, I should be able to access the vector and increment counters, add more line numbers, whatever.
Thanks.
Similar Messages
-
Dynamic creation of class and calling methods
I've got and interface called Transformation and then two implementations called TxA and TxB, where TxA and TxB have their own attribtues and setter and getters for these attributes.
The question is, I need to create instances of TxA and TxB and called the setter and getters where I at runtime I only know the attribute to set, how can I create and instance and call the right getters and setters methods?
Thanks in advanceSmart money says your design sucks and needs to be rethought entirely. Can we get specifics?
Drake -
How can i interact with the ALV if i am using the lvc_ and call method?
i want to hide the last entry of a line when i click on the checbox of my ALV
u want to hide or delete?
instead of using check box, u can use a button to display there.
it can be achived like below.
data: ls_lvclayout type lvc_s_layo.
LS_LVCLAYOUT-SEL_MODE = 'D'.
now in set_table for_first_diaplay
CALL METHOD GO_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
<b> IS_LAYOUT = LS_LVCLAYOUT</b>
do like above.
then u click on the row, and the row will be selected.
now using the method GET_SELECTED_ROWS, u can get the data of the selected row and u can now manipulate what ever u needed.
data:
SEL_ROW TYPE LVC_S_ROID,
SEL_T_ROW TYPE LVC_T_ROID.
CALL METHOD GO_GRID->GET_SELECTED_ROWS
IMPORTING
ET_ROW_NO = SEL_T_ROW.
LOOP AT SEL_T_ROW INTO SEL_ROW.
read table <itab> index SEL_ROW-ROW_ID.
check sy-subrc = 0.
< now write the logic like making the field blank and modify the itab>.
ENDLOOP. -
Legacy C program - new Java GUI and calling methods
Hello,
I am fairly new to these forums. I've been working for a company that has an exsisting program that is a propriotery video-client to a video-server. It is written in C and has DirectX components for the standalone C application and ActiveX components for the Internet Explorer version.
I looked over the source code and found a main() function. Now I am trying to execute that main() fuction through java and jni. I have managed to get a simple HelloWorld program to work but am now stuck.
I would like to do the following.
1. Convert the exsisting code to a C library. I have to use Visual C++ 6.0 to create this project. (There is already an exsisting dsw project file for the video client).
Question: How do I get rid of the main() function and compile correctly in Visual C++?
2. How do I call the library function that I created in the above from a java main() method? What should I use to edit and compile java/c code?
Thank you,
ViralHi,
If you need to have fast results you can try to use the ActiveX with COM bridge like Jawin or JACOb (both at sourceforge) or use Eclipse's SWT that has an activeX support too.
An other alternative is to create a full JNI wrapper to your project.
A1 : Replace the main by DllMain (create a new DLL with msvc++ wizard to see how to create a basic DLL).
A2 : Call all functions exported by DLLs with a free tool like JNative.
--Marc (http://jnative.sf.net) -
hi evreyone
I need to create an editable tree based on (one table called Locations)
this is the structure of this table
LocationNo
LocationName
ParentLocationNo
LocationNo and ParentLocationNo are Forign keys
according to what I've red I should use a recursive tree (Self-Reference forign key)
using a view that represent the tree (nodes & branches)
how can I create this tree (with Details Steps) ?
I am using
Jdeveloper 11.1.1.2.0
JHeadstart 11.1.1.2.29
thankshi
According to chapter 5 "Creating Tree Layouts", 5.7.4 "Variation: Recursive Tree"
I've created a Recursive Tree based on table call (Location)
but the problem is how can I refresh the data ... I mean .. How can I See the new record that I've
created in the same tree without moving in it (to make a refresh)
thanks -
How do I call methods on a EJB?
Hello!
I have a couple of classes that I think would be nice of sharing among sevral sites at my Weblogic 8.13
There fore I guess it would be nice to assamble them in a EJB.
For eg I have this class DatabaseAccessor that I guess would be nice to use like a EJB.
So I craeted the following classes and deployed like a EJB on server A.
DatabaseAccessorEJB implements SessionBean
DatabaseAccessorRemote extends EJBObject
DatabaseAccessorHome extends EJBHome
On server B and server C I have webapp B and webapp C.
But I do not manage to figure out how to instanitiate them and call methods on them?
Does any body recognize this particular scenario and could advise me some tutorial or some hints?
Best regards
Fredrik
Edited by fredand44 at 04/09/2007 11:28 AMCheck the sample Client code in your installation under following directory
weblogic81\samples\server\examples\src\examples\ejb20\basic\statelessSession\Client.java -
Passing values and calling other classes?
Hello all.
I have 2 classes(separate .java files). One is a login class and the other is the actual program. Login class(eventually exe file) should open the other class and pass the login parameters if you know what I mean. Is this possible, or do the 2 classes need to be part of one file?
Thanks alot
Milan DLogin class can be another class in another file
wht u have to do is to make an instance of login class in the class u want to use that class
like login lg = new Login();
and call method of login class
lg.setUser(username);
where setUser(String user); is a method of login class
this way u can pass the parameters to login class
i hope this might be helpful
regards
Moazzam -
Pass a variable name to a subroutine and use a method on it...
How do I pass a variable name to a subroutine and then call a method on it?
I have several swing text fields in a JForm. When someone enters a string in any of these fields, I want to check whether it is a number and, if now, clear that individual field and display a popup warning.
So, I want to do something like....
String stringcheck(String str, sometype variablename) {
try {
Integer.parseInt(str);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(jPanel2, "These fields must be integer numbers.");
variablename.setText("");
}prometheuzz wrote:
tsith wrote:
prometheuzz wrote:
NickSchurch wrote:
thanks prometheuzz. I'm returning a string cos there are some other parts to the subroutine.Ah, now I understand.
Well, good to hear you found a solution to it.You know, you really should have seen that from post 1.
No offense, but seriously - does he have to draw you a picture?!
I probably wouldn't understand the picture either: I'm not much of an art critic. Unless the OP is [Bob Ross|http://www.bobross.com/], his paintings, I understand.
"I'm returning a string 'cos there's a happy tree over there, and I think I'll put a happy rock right here" -
Binary Tree search and print methods
Hello, I'm trying to create a binary tree from inputs of a user. I believe I have the tree set up right because it shows no errors, but I'm getting an error message with a line of code. I cannot figure out what I am doing wrong. Also, I need to create a print method, which prints the tree's entries and a search method which would search the tree for certain record.
public class TreeNode
public static String empName = null;
public static int empNumber;
public static String nextRec = null;
TreeNode left;
String Name;
int Number;
TreeNode right;
public static void main(String[] args)
VRead in = new VRead();
VWrite out = new VWrite();
System.out.println("Enter Choice: ");
System.out.println("A: Enter Employee Information.");
System.out.println("B: Search For Employee.");
System.out.println("C: Print Entire Tree.");
System.out.println("D: Exit.");
System.out.println("_______________________________");
char command = in.readChar();
System.out.println();
switch (command)
case 'A':
case 'a':
inputInfo(in, out);
break;
case 'B':
case 'b':
break;
case 'C':
case 'c':
break;
case 'D':
case 'd':
System.exit(0);
break;
public static void inputInfo(VRead in, VWrite out)
out.write("Enter Employee Name: ");
empName = in.readString();
out.write("Enter Employee Number: ");
empNumber = in.readInt();
System.out.println();
System.out.println();
System.out.println("Enter Choice: ");
System.out.println("A: Enter Employee Information.");
System.out.println("B: Search For Employee.");
System.out.println("C: Print Entire Tree.");
System.out.println("D: Exit.");
System.out.println("_______________________________");
char command = in.readChar();
System.out.println();
switch (command)
case 'A':
case 'a':
inputInfo(in, out);
break;
case 'B':
case 'b':
break;
case 'C':
case 'c':
break;
case 'D':
case 'd':
System.exit(0);
break;
public TreeNode(String empName, int empNumber)
Name = empName;
Number = empNumber;
left = null;
right = null;
public class Tree
TreeNode Root;
public void Tree(String RootNode)
// Errors come from next line
Root = new TreeNode(RootNode, Name, Number);
public void Insert(String Name, int Number)
InsertNode(Root, Name, Number);
public void InsertNode(TreeNode t, String empName, int empNumber)
if (t == null)
t = new TreeNode(empName, empNumber);
else
if (empName.compareTo(t.Name) < 0)
InsertNode(t.left, empName, empNumber);
else if (empName.compareTo(t.Name) > 0)
InsertNode(t.right, empName, empNumber);
else if (empName.compareTo(t.Name) == 0)
System.out.println("Entered node that was already in Tree");
}im sure its something simple, i seem to always look over the small stuff. But i could really use some help on the print and search method tooJust having a quick look over it, and it looks like you are trying to add an extra argument in the TreeNode() method (unless there is a bit of overloading and there is a second treenode method in there) As it is TreeNode only accepts two argumets you have 3
As for printing the tree you would need to flatten it, that is an in order traversal of the tree.
FWIW
I just finished a project at uni that involved at frist writing a BST and then an AVL tree. the full point of these things seems to be to keep students awake at night*
*Before anyone flames, it's a joke
G -
Session method and call transaction methos which one is the sap recomonded
hi
PLease give me the answer to these questions.
session method and call transaction methos which one is the sap recomonded why .
2) if we want to maintain BDC program in all the systems.wt to d0Hi Revethi,
Here is the difference between the Session and Call Transaction method.
Session
Session method supports both small amount of data aswell as large amount of data
2) data processing is asynchronus and data updation is synchronus.
3) it process multiple apllication while perfomaning validations.
4) in session method data will be updated in data base only after processing session only.
5) system provide by default logfile for handling error records.
6) it supports both foreground aswell as background process
in bdc we use FM ... bdc_open_group " for creating Session
bdc_insert " adding transaction and bdcdata table for updating database
bdc_close_group " for closing Session
Call Transaction
Call transaction exclusively for small amout of data
2) it supports only one apllication while perfoming validations
3) there is no default logfile, We can explicitly provide logic for creating logfile for handling error records.
we can create logfile by using structure....BDCMSGCOLL
4) it doesn't support background processing.
5) data processing is synchronous and Data updation is Synchronous( default), in
this method also supports daya updation in asynchronus process also.
Syntax:
Call transaction <transaction-name> using BDCDATA
mode <A/N/E> update <L/A/S>
messages into BDCMSGCOLL. -
Error while updating data using session and call transaction method
Hi all,
i have to update data using MM01 transaction from flat file to database.i have used both session method and call transaction method to do that.in both the methods data has been transferred from internal tables to screens but while updating the data that is by clicking the ok-code at the end of the transaction iam getting a dialogue box stating
SAP EXPRESS DOCUMENT "UPDATE WAS TERMINATED" RECEIVED FROM AUTHOR "SAP".
please tell whether the problem lies and solution for that.
thanks and regards.hi,
check your recording.check whether u saved your material no in recording or not.
once again record the transacton mm01.
MATNR LIKE RMMG1-MATNR,
MBRSH LIKE RMMG1-MBRSH,
MTART LIKE RMMG1-MTART,
MAKTX LIKE MAKT-MAKTX,
MEINS LIKE MARA-MEINS,
MATKL LIKE MARA-MATKL,
BISMT LIKE MARA-BISMT,
EXTWG LIKE MARA-EXTWG,
these are the fields which u have to take in internal table.
this is the record which i took in my flatfile.use filetype as asc and hasfieldseperator as 'X'.
SUDHU-6 R ROH MATSUDHU " 001 7890 AA
i did the same.but i didn't get any error. -
Error in CALL TRANSACTION and SESSION Method
I have 8 records (1,2,3,4,5,6,7,8) to update into SAP database using CALL TRANSACTION and SESSION Method. If there is a error in 6th record. What happens in both call transaction and session method.
Please let me know which records will process and what about the error record. How to process only the error record if all other records have updated into database.Hi Patil_sumeet,
if your code for this is not protected secret of some federal agency, you may read [How to post code in SCN, and some things NOT to do...|How to post code in SCN, and some things NOT to do...; and then post relevant lines here.
According to the facts presented until know it may have been better to ask Radio Eriwan
Regards
Clemens -
Call method http_client- response- get_header_fields for PDF and for TIFF
Hi,
I am using a Function Module..
APAR_EBPP_GET_INVOICE_DETAIL to display the TIFF images on the Biller Direct side.
The above function module is used to retrieve the PDF documents from the document repository.
In Similar way I am trying to do the TIFF Images too.
But in this method
call method http_client->response->get_header_fields
changing fields.
For PDF the table fields is as follows
NAME VALUE
1 ~response_line----
|HTTP/1.1 200 (OK) |
2 ~server_protocol----
|HTTP/1.1 |
3 ~status_code----
|200 |
4 ~status_reason----
|(OK) |
5 content-length----
|7136 |
6 content-type----
|application/pdf |
7 server |Microsoft-IIS/6.0 |
8 x-powered-by |ASP.NET |
9 date |Tue, 24 Feb 2009 18:09:35 GMT |
10 connection |close |
For TIFF the table fields are as follows:
1 ~response_line----
|HTTP/1.1 500 (internal server error) |
2 ~server_protocol----
|HTTP/1.1 |
3 ~status_code----
|500 |
4 ~status_reason----
|(internal server error) |
5 content-length----
|105 |
6 content-type----
|text/plain |
7 server----
|Microsoft-IIS/6.0 |
8 x-powered-by |ASP.NET |
9 date |Tue, 24 Feb 2009 18:26:39 GMT |
10 connection |close |
The error message is Internal Server error..
This is in HTTP2_Get Function Module.
What would be the reason for HTTP/1.1 500 Internal Server error.
Any suggestions are welcome..
Thanks,
ChaitanyaHi Niranjan,
can you please check if you have imported the whole chain of certificates. Certificates usually diplayed in 3 levels in the Explorer. like
Verisign - L1
>>> Versign-- L2
>>>>>>>>>>>>XYZ.com -- L3
Extract all the 3 certificates and Put in Strust and do exit soft and hard in SMICM and restart the service.
Its better to create a RFC destination of Type H and Do the Connection test for HTTPS configuration. If the connection test comes OK then u can be sure of the configuration. -
Working with class based exception and dynamic method calls
Hi Gurus,
we just changed out ERP from EHP6 to EHP7.
Since we did so we are facing an issue with an Z-Report we are using quite often.
This reports looks up Workitems and executes the according methods so that we can go into debugging if we were facing any problems or errors.
since the EHP Upgrade this statement has problems:
data: lt_parmbind type abap_parmbind_tab, lt_excpbind type abap_excpbind_tab, lo_runtime type ref to object. call method lo_runtime->(iv_cls_method) parameter-table lt_parmbind exception-table lt_excpbind.this CALL METHOD Statement has Problem with the Exception Table. We are quite often getting DYN_CALL_METH_EXCP_NOT_FOUND short dumps with Exception "CX_SY_DYN_CALL_EXCP_NOT_FOUND".
The system has problems handling the content of lt_excpbind. if i clear this table the CALL METHOD statement works fine.
AS an example we are trying to call /IDXGC/CL_PD_PROCESS_STEPS-->CREATE_DATA. This method has 2 exceptions
/IDXGC/CX_PROCESS_ERROR
Process Layer Exception
CX_BO_TEMPORARY
Temporary Business Exception
The Content of LT_EXCPBIND is
INDEX
NAME
VALUE
2
/IDXGC/CX_PROCESS_ERROR
1
2
CX_BO_TEMPORARY
2
From my point of view the Problem ist, that they are marked as "class based". I think so because if you looked up the SAP Help for the EXCEPTION-TABLE Statement it is written that is statement only works for none-classbased exception.
I think that restriction is quiet clear. But what i am wondering about is.. that restriction also exists for EHP6. And in EHP6 it work. Does anyone know why? Or how i can change me CALL METHOD Statement that i will work again?
Best Regards
UdoClass-based exceptions must be caught using try/catch statement.
Calling dynamically a method catchable exceptions are:
CX_SY_DYN_CALL_EXCP_NOT_FOUND
CX_SY_DYN_CALL_ILLEGAL_CLASS
CX_SY_DYN_CALL_ILLEGAL_METHOD
CX_SY_DYN_CALL_PARAM_MISSING
CX_SY_DYN_CALL_PARAM_NOT_FOUND
CX_SY_REF_IS_INITIAL
Anyway catching cx_root (as shown by Matthias) will catch everything is catchable. -
EJB 3.1 @Asynchronous and calling other methods from within
Hey all,
I am helping a friend set up a test framework, and I've turned him on to using JEE6 for the task. I am decently familiar with entity beans, session beans, and such. One of the new features is @Asynchronous, allowing a method to be ran on a separate thread. The test framework generally needs to spawn potentially 1000's of threads to simulate multiple users at once. Originally I was doing this using the Executor classes, but I've since learned that for some reason, spawning your own threads within a JEE container is "not allowed" or bad to do. I honestly don't quite know why this is.. from what I've read the main concern is that the container maintains threads and your own threads could mess up the container somehow. I can only guess that this might be possible if your threads use the container services in some way.. but if anyone could enlighten me on the details as to why this is bad, that would be great.
None the less, EJB 3.1 adds the async capability and I am now looking to use this. From my servlet I use @EJB to access the session bean, and call an async method. My servlet returns right away as it should. From the async method I do some work and using an entity bean store results, so I don't need to return a Future object. In fact, my ejb then makes an HttpClient call to another servlet to notify it that the result is ready.
My main question though, is if it's ok to call other methods from the async method that are not declared @Asynchronous. I presume it is ok, as the @Asynchronous just enables the container to spawn a thread to execute that method in. But I can't dig up any limitations on the code within an async method.. whether or not it has restrictions on the container services, is there anything wrong with using HttpClient to make a request from the method.. and making calls to helper methods within the bean that are not async.
Thanks.851827 wrote:
Hey all,.. from what I've read the main concern is that the container maintains threads and your own threads could mess up the container somehow. I can only guess that this might be possible if your threads use the container services in some way.. but if anyone could enlighten me on the details as to why this is bad, that would be great.
Yes since the EE spec delegated thread management to conatiners, the container might assume that some info is available in the thread context that you may not have made available to your threads.
Also threading is a technical implementation detail and the drive with the EE spec is that you should concentrate on business requirements and let the container do the plumbing part.
If you were managing your own threads spawned from EJBs, you'd have to be managing your EJBs' lifecycle as well. This would just add to more plumbing code by the developer and typically requires writting platform specific routines which the containers already do anyway.
>
None the less, EJB 3.1 adds the async capability and I am now looking to use this. From my servlet I use @EJB to access the session bean, and call an async method. My servlet returns right away as it should. From the async method I do some work and using an entity bean store results, so I don't need to return a Future object. In fact, my ejb then makes an HttpClient call to another servlet to notify it that the result is ready.
My main question though, is if it's ok to call other methods from the async method that are not declared @Asynchronous. I presume it is ok, as the @Asynchronous just enables the container to spawn a thread to execute that method in. But I can't dig up any limitations on the code within an async method.. whether or not it has restrictions on the container services, is there anything wrong with using HttpClient to make a request from the method.. and making calls to helper methods within the bean that are not async.
Thanks.If you want to be asynchronous without caring about a return value then just use MDBs.
The async methods have no restrictions on container services and there is nothing wrong with calling other non async methods. Once the async method is reached those annotations don't matter anyway (unless if you call thhose methods from a new reference of the EJB that you look up) as they only make sense in a client context.
Why do you need to make the call to the servlet from the EJB? Makes it difficult to know who is the client here. Better use the Future objects and let the initial caller delegate to the other client components as needed.
Maybe you are looking for
-
HP ProBook 6460b: How do I turn off/disable trackpad clicking?
I originally asked this question here: http://www.tomshardware.com/answers/id-2628935/laptop-turn-disable-clicking-touchpad.html There was one response: "There should be a Synaptics icon in the taskbar or the bottom right of the screen. Go there and
-
Problem logging into Workflow Designer
Hi, here is my problem. Workflow 7.0 is installed on W2k3 EE (with Forms and Form Manager) via turnkey installation ( and is on Jboss of course). I've got four other computers in domain. All with XP. And only from one i can login into Workflow Design
-
my music has disappeared from my computer but not from my ipad...how do i transfer it back
-
AS3: How to get height of a dynamically created text field
I am importing text from an XML file and want the lines of text to display in separate text fields beneath each other. How can I set the y value of each succeeding text field so that there is some space (40 pixels or so) from the above field, regardl
-
I am new to webdynpro ABAP can someone give the good material ?
Hi, i am new to webdynpro ABAP can someone give the good material ? Please tell me what knowledge do i need to learn webdynpro ABAP? Regards, Chow.