Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9202565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:17:13+00:00 2026-06-17T23:17:13+00:00

I am trying to write a boolean method isSubset (returns a boolean value if

  • 0

I am trying to write a boolean method isSubset (returns a boolean value if every element in set A is in set B and false otherwise) where method call can be written like this setA.subsetOf(setB). My thought is to extract each element of setA and compare it with setB. If the first element of setA is matched with any in setB, proceeding to next element in setA to check. If all elements in setA is matched with any element from setB, method returns true, else (not all elements from setA is in setB) returns false. I already wrote the method to check for containment of an element to a linked list as followed:

  public boolean contain (Object target) {
      boolean status = false;
      Node cursor;
      for (cursor = head; cursor.getNext() != null; cursor = cursor.getNext()) {
          if (target.equals(cursor.getElement())) 
              status = true;
      }   
      return status;
  }

Since im still confused about the syntax of linked list operation, my question is how to extract each element and do the rest. Any help would be appreciated.
Node is declared

  public Node(Object o, Node n) {
    element = o;
    next = n;
  }

SLinkedList

  public SLinkedList() {
    head = new Node(null, null); // create a dummy head
    size = 0;
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:17:14+00:00Added an answer on June 17, 2026 at 11:17 pm

    First, your contain method has a small bug in it. The for condition cursor.getNext() != null; should be cursor != null;. Doing so prevents the search of empty sets (which would cause your code to crash) as well as allowing the last Node in the list to be searched. Your code would run faster if you did return status; after status=true;

    The structure for isSubset would be very similar to the loop you created; the loop would look like this:

    for(cursor = head; cursor!=null; cursor.getNext()){
      if(setB.contain(cursor.getElement()) == false){
        return false;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to write a simple method: boolean validate(MyObject o) { // propertyA
I'm trying to write a method named isLowerThanFreezing that returns true if the Temperature
I am trying to write a method with the following header: public static boolean
I'm trying to write a method that takes 2 ArrayLists of doubles and returns
I'm trying to write a button_to statement that updates a boolean value in my
I'm trying to write an implementation of iterator so that I can call it
I m trying write code that after reset set up rrpmax as 3000. It
Trying to write a chat, like on facebook, I wondered if two clients can
I'm trying to write a method that will take in two Queues (pre-sorted Linked
Hi i am trying to write a palindrome method but am getting the wrong

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.