Write two functions to find the the number of elements in a linked list?

I am trying to Write two functions to find the the number of elements in a linked list. One method using recursion and One method using a loop...
//The linked List class is Represented here.
public class lp {
public int first;
public lp rest;
public lp(int first1, lp rest1)
first = first1;
rest = rest1;
The program i wrote so far is
import java.util.*;
import linklist.lp;
public class listCount{
//loop function
public static void show_list(lp list)
int counter = 0;
while(list != null)
list = list.rest;
counter++;
System.out.println ("length computed with a loop:" + counter);
//recursive function
public static int recursive_count(lp list)
if (list.first == null)
return 0;
else
return recursive_count(list.rest) + 1;
//main method
public static void main (String args[])
lp list1 = new lp(1, new lp(2, new lp(3, null)));
show_list(list1);
System.out.println("length computed with a recursion:" +
recursive_count(list1));
at the if (list.first == null) line i get the error " incomparable types:
int and <nulltype>" I know this is a beginners error but please
help...What should I do?

byte, char, short, int, long, float, double, and boolean are primitives, not objects. They have no members, you cannot call methods on them, and they cannot be set to or compared with null.

Similar Messages

  • How do I find the total number of elements in a multi dim array

    How do I find the total number of elements in a single or multi dim array?
    For example, a 2x3 array has 6 elements, and a 2x3x4 has 24. How do I compute this very easily - is there a single VI that does this?
    David
    Solved!
    Go to Solution.

    Use "array size" (array palette) followed by "multiply array elements" (numeric palette)
    (Works also equally well for 3D arrays and higher)
    For a 1D array, just use "array size".
    Message Edited by altenbach on 02-05-2009 05:57 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    NumberOfElements.png ‏3 KB

  • Write a procedure to find out the data copy is happening or not.

    Good Day all,
    I have two databases called "*Report*" and "*Production*". I have a report database which copy a data from production database. I want to write a Stored procedure to compare the count of one table in both the databases. All the tables are same in both the databases.
    Please note :*
    1. We are writing the procedure to find out the data copy is happening or not and also report database is down or not.
    2. Not all times, the both the count is same, sometimes it take delay to copy the data in report database but report database is not down.
    Please see the query to compare
    _"Report"_
    Select count(*) from trx where date ='03-Oct-2010'
    *"Production"*
    Select count(*) from trx where date ='03-Oct-2010'
    I am suggesting to take a count for every 5 mins and keep in temp table and compare it.
    Thanks
    Nihar

    How are you replicating the data from the production database to the reporting database?
    Wouldn't it make more sense to monitor that replication process rather than counting every row in the table every 5 minutes? That's going to get rather expensive for non-trivial tables. If you are using something like Streams to replicate the data, it would make far more sense to monitor the Streams apply process, to determine when the reporting database it updated as of, than it would to monitor the underlying tables.
    Justin

  • Cannot find the serial number on Elements 11 to install.

    Have tried all the numbers i can see but no joy. Can anyone help ?

    Hi DANNYJOHN5130,
    The E-mail address provided was examined by me , there is no serial number registered under retail or volume licenses.
    How ever you can try to retrieve the serial number (if you have purchased a serialized product) from the steps in the below mentioned link.
    http://helpx.adobe.com/x-productkb/global/find-serial-number.html
    Hope it helps you.
    Regards,
    Rajshree

  • When I use the function of "finding keyword", the word would be shown in green. Can I set the colour by myself?

    When I use the function of "finding keyword"(ctrl+f), the keyword would be shown in green. I want to change the highlighted colour to be blue. Is there any function to change the colour?

    See '''''cor-el's''''' answer in this thread: https://support.mozilla.com/en-US/questions/900541
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''
    Not related to your question, but...
    You may need to update some plug-ins. Check your plug-ins and update as necessary:
    *Plug-in check --> http://www.mozilla.org/en-US/plugincheck/
    *Adobe Shockwave for Director Netscape plug-in: [https://support.mozilla.com/en-US/kb/Using%20the%20Shockwave%20plugin%20with%20Firefox#w_installing-shockwave Installing ('''''or Updating''''') the Shockwave plugin with Firefox]
    *Adobe PDF Plug-In For Firefox and Netscape: [https://support.mozilla.com/en-US/kb/Using%20the%20Adobe%20Reader%20plugin%20with%20Firefox#w_installing-and-updating-adobe-reader Installing/Updating Adobe Reader in Firefox]
    *'''''Shockwave Flash''''' (Adobe Flash or Flash): [https://support.mozilla.com/en-US/kb/Managing%20the%20Flash%20plugin#w_updating-flash Updating Flash in Firefox]
    *Next Generation Java Plug-in for Mozilla browsers: [https://support.mozilla.com/en-US/kb/Using%20the%20Java%20plugin%20with%20Firefox#w_installing-or-updating-java Installing or Updating Java in Firefox]

  • I can't find the serial number of Elements trial download.

    I downloaded a trial of Elements 13.  I am trying desperately to pay for it.  I cannot figure out where to find the serial number.  It does not show up in my Adobe account. What do i do?

    Well, the problem solved itself when I phoned Adobe and got talked into the Cloud.  I think, though no proof, that perhaps ordering Elements automatically malfunctions so you get to talk to a real person and they convince you the Cloud is the way to go.  I did not realize I could use the Cloud software when not connected to the Internet, and that was my main reason for not taking that route.  Also, according to the person on the phone, I can use it both my PC and my Mac, so that's a real plus.
    Thanks to those who tried to solve my problem.

  • How do i delete messages from i phone and clear the name/number from appearing in my message list?

    How do i delete messages from i phone 4 but make sure the line/number/details clears from my list on messages so i don't have a long list in there??

    To delete a conversation, you can either swipe left to right, and delete the conversations, or use the edit button.  If you have a conversation selected, edit will allow you to delete specific messages.

  • How do I deactivate the serial number for Elements 8?

      How do you deactivate a serial number from Elements 8?  Tried 'help' while in Elements 8, as instructed, and it just sends me to the website for Elements 12. 

    Open the Editor and click the menu bar:
    Help >> Deactivate

  • How to write a function to find weekday

    my code as follow:
    create or replace function getweekday(arg_day_IN VARCHAR2)
    RETURN varchar2
    IS
    arg_day VARCHAR2(8) := arg_day_IN;
    ls_week VARCHAR2(1);
    ls_week_name VARCHAR2(4);
    ls_date_1 date;
    BEGIN
    ls_date_1 := to_char(SUBSTR(arg_day, 5, 2) || '-' || SUBSTR(arg_day, 7, 2) )|| '-' ||SUBSTR(arg_day, 1, 4));
    ls_week := OMWB_emulation.utilities.WEEKDAY(ls_date_1);
    RETURN ls_week;
    END getweekday;
    There is a problem that when i execute this function it returns a error code ora-01843, it shows that it is not a valid month.
    How can I know what is a valid month format? How to find the correct month format?
    Which one is the valid date format- 02-01-2004 or 02-Jan-2004 or 02-January-2004.
    Please help me to solve this problem. Thanks a lot.

    If the input parameter format is 'yyyymmdd' you can do:
    create or replace function getweekday(arg_day_IN VARCHAR2)
    RETURN varchar2
    IS
    ls_week VARCHAR2(1);
    BEGIN
    ls_week := to_char(to_date(agr_day_IN,'yyyymmdd'),'D');
    RETURN ls_week;
    END getweekday;

  • How to decide the maximum number of elements for DMA FIFO in R series FPGA

    Greetings!
    I'm working on a project with NI R series PCIe-7842R FPGA board. To achieve fast data transfer I'm using target-to-host DMA FIFO. And to minimize the overhead, I'd like to make the FIFO size as large as possible. According to the manual, 7842R has 1728 kb (216KB) embedded block RAM, i.e., 108,000 I16 type FIFO elements available in theory (1728,000/16). However the FPGA had compilation error when I requested such amount of elements. I checked the manual and searched online but couldn't find the reason. Can anyone please explain? And in general, what's the max FIFO size given the size of the block RAM?
    Thanks! 

    Hey iron_curtain,
    You are correct that moving larger blocks of data can lead to more efficient utilization of the bus, but that's almost certainly not the most important factor here. Assuming of course that the FIFO on the FPGA is big enough to avoid overflows, I'd expect the dominant factor to be the size of read performed on the host. In general, larger reads on the host lead to improved throughput, up to the speed of the bus. This is because FIFO.Read is a relatively expensive software operation, so it's advantageous to make fewer calls to get the same amount of data.
    Note that the larger your call to FIFO.Read the larger the host buffer needs to be. Depending on your application, it might need to be several times larger than the read size. You can set the buffer size with the FIFO.Configure node.
    http://zone.ni.com/reference/en-XX/help/371599H-01/lvfpgaconcepts/fpga_dma_how_it_works/ explains the various buffers involved. It's important to note that the DMA Engine moves data asynchronously from the read/write nodes on the host and fpga.
    Let me know if you have any questions about any of this.
    Sebastian

  • Count the number of elements in comma seperated list of values

    Hello Friends,
    I have a string with comma seperated list of values say
    String v = 34343,erere,ererere,sdfsdfsdfs,4454,5454,dsfsdfsfsd,fsdfsdfsdfs,dfdsfsdfsdfs,sdsfdsf,ererdsdsd45454,fsdfsdfs
    Want to count how many elements are existing in this string .
    Thanks/Kumar

    Hi, Kumar,
    REGEXP_COUNT, which Hoek used, is handy, but it only works in Oracle 11. Which version of Oracle are you using?
    In any version of Oracle, you can count the commas by seeing how much the string shrinks when you remove them.
    LENGTH (str) + 1 - LENGTH (REPLACE (str, ',')) Can str have multiple commas in a row? What if there's nothing between consecutive commas, or nothing by whitespace? Can str begin or end with a comma? Can str consist of nothing but commas? Depending on your answers, you may have to change things. You might want
    REGEXP_COUNT ( str
                 , '[^,]+'
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

  • What is the max number of recipients in an email list

    Mail is rejecting my email because of too many recipients. What is the limit??

    http://support.apple.com/kb/ht4863

  • How do I extract the length of an element in an Array List

    Hello there,
    I am facing this problem with an Array List of elements. I am trying to extract the individual length of a particular element in the array list . Now if I know the element is a String is this valid?
    int lengthOfElement = 0;
    lengthOfElement = ((String)parms.get(i)).length();
    Your answer is much appreciated
    Regards

    Snap!I don't know how many times I've seen people post
    saying that they have a list where each element is a
    String, but they keep on getting ClassCastException :)Damn those Integers!
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Wait for 30 seconds to execute the two functions

    Dear Sir
    I have a package in which two functions are written.Once the first function is executed I wanted the second function to wait for 30 seconds to execute the second functions.Could you please tell me how can I do it?
    Regards

    Go to $ORACLE_HOME/rdbms/admin and read the header:
      --  DESCRIPTION
      --    These routines allow the user to request, convert and release locks.Granting privileges on USER_LOCK is, at least according to the docs I've read, intended to limit the amount of damage a user with execute privs can do.
    You can, of course, find SLEEP in four different Oracle packages:
    * dbms_backup_restore
    * dbms_drs
    * dbms_lock
    * user_lock -- note the granularity is different from dbms_lock and the othersI have documented all of them here:
    http://www.morganslibrary.org/reference/sleep.html
    I think people point those that ask questions to DBMS_LOCK only because it is the one best known.

  • How to find the serial number

    I cant find the serial number on the back of the dvd case? Which one is that?

    justperso
    What version of Premiere Elements do you have and what computer system is involved?
    I have Premiere Elements in the box packaging for versions 4 through 12, so once you supply the information requested, I will give you exact details on where to find the serial number.
    Here is a link to give you the general idea
    https://helpx.adobe.com/x-productkb/global/find-serial-number.html
    ATR

Maybe you are looking for

  • Is it time for a new one?

    Imac is blue and screaming every morning. Unplug turn it on its OK all day. Is it time to replace it?

  • Replacing a person in a photo

    Ok guys, Newbie here. I have no business tyring to do this, but it's for an 60th wedding anniversary announcement for my inlaws. I have a couple pictures of the happy couple in a group. I managed to cut the group out and just leave the two and add so

  • Where to put javascript?

    Following suggestions on this forum I put some javascript functions in the header part of my theme. This somehow doesn't seem right. 1) Once you switch theme your app. stops working. 2) Themes should be about the look of your app. and not about the f

  • Read stament insted of loop

    Hi,    Iam woking one exit.My requirement is 1. Check if operating concern (I_ERKRS) is 0001 than go to step 2 else go to        step  4. 2. Read CE10001 table and verify value for Item Category (CE10001-PSTYV). 3. If Item Category(CE10001-PSTYV) is

  • RAS Server Issue - Uninstall/Install RAS

    Hi, I've posted a RAS Server issue several weeks ago and still, I haven't gotten my answer. With this, is it safe/possible to uninstall and install RAS Server? is it safe? Thanks, Ken