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 8627309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:14:43+00:00 2026-06-12T08:14:43+00:00

I am trying to compare two objects of my class CustomerNode, and then return

  • 0

I am trying to compare two objects of my class CustomerNode, and then return a result related to the alphabetic superiority of these methods. I cannot figure out exactly why this isn’t working. To me, the logic seems good, and I am following the instructions set forth in my homework.

    bool OrderedList::add (CustomerNode* newEntry)
{
if (newEntry != 0)
{
    CustomerNode * current;
    CustomerNode * previous = NULL;
    if(!head)
        head = newEntry;
    current = head;
  // initialize "current" & "previous" pointers for list traversal
   while(current && *newEntry < *current) // location not yet found (use short-circuit evaluation)
   {
    // move on to next location to check
    previous = current;
    current = current->getNext();
   }

  // insert node at found location (2 cases: at head or not at head)
  //if previous did not acquire a value, then the newEntry was
  //superior to the first in the list. 
  if(previous == NULL)
    head = newEntry;
  else
  {
    previous->setNext(newEntry); //Previous now needs to point to the newEntry
    newEntry->setNext(current); //and the newEntry points to the value stored in current.
  }
}
    return newEntry != 0;  // success or failure
    }

Okay, here is the overloaded operator< included in the program, testing it on generic objects turns up expected results:

    bool CustomerNode::operator< (const CustomerNode& op2) const
    {
       bool result = true;
       //Variable to carry & return result
       //Initialize to true, and then:
       if (strcmp(op2.lastName, lastName))
        result = false;

        return result;
       }

I am very new to programming, so I appreciate any responses, especially style critiques since I am still learning that. Is my logic just wrong, or are there other rules that I need to be aware of? I do not entirely understand why my parameters are reference, or if I actually need to dereference the parameter to call the operator.

Thanks.

  • 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-12T08:14:45+00:00Added an answer on June 12, 2026 at 8:14 am

    Your condition is wrong:

    if (strcmp(op2.lastName, lastName))
    

    For different strings, regardless of their ordering, this will return not-false (true), and your function will return false.

    A correct condition would be:

    if (strcmp(op2.lastName, lastName) >= 0)
    

    Or you can just re-write the whole thing:

    bool CustomerNode::operator< (const CustomerNode& op2) const
    {
       return  strcmp(op2.lastName, lastName) < 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to compare two vector objects, and return a single vector containing
So I'm trying to figure out how to compare two jQuery objects, to see
I am trying to compare two variables in which are usually strings. These variables
I'm trying to compare objects of a common base class together. The comparison should
When trying to compare two objects passed as arguments: first as object, second as
I'm trying to compare two subclasses of Number inside a class with generics. In
I am trying to compare two tools execution time, which I have installed in
I'm trying to compare two different column types (not my doing, part of a
I am trying to compare two text files and output the first string in
I am trying to compare two strings in a simple shell script. I was

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.