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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:24:08+00:00 2026-05-26T10:24:08+00:00

In the following code: void insert(Node *& aNode, int x) { if (!aNode) {

  • 0

In the following code:

void insert(Node *& aNode, int x) {
  if (!aNode) {
    aNode = new Node(x);
    aNode->next = aNode;
    return;
  }

  Node *p = aNode;
  Node *prev = NULL;
  do {
    prev = p;
    p = p->next;
    if (x <= p->data && x >= prev->data) break;   // For case 1)
    if ((prev->data > p->data) && (x < p->data || x > prev->data)) break; // For case 2)
  } while (p != aNode);   // when back to starting point, then stop. For case 3)

  Node *newNode = new Node(x);
  newNode->next = p;
  prev->next = newNode;
}

What is Node *& aNode?

How should I use this function, I mean, which type of parameter should I pass?

  • 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-05-26T10:24:08+00:00Added an answer on May 26, 2026 at 10:24 am

    I think this code is C++, not C, and Node *&aNode is a reference to a pointer to a Node, so you would pass a Node* to the function, and function would make a reference to that (so the memory location your Node* is pointing to can change).

    You may find the Wikipedia article on References (C++) interesting.

    A simple example:

    #include <iostream>
    void addOneToValue(int num) {
        ++num;
    }
    
    void addOneToRef(int &num) {
       ++num;
    }
    
    int main() {
       int num = 0;
    
       // print 0
       std::cout << num << std::endl;
    
       // print 0 again (addOneToValue() has no effect)
       addOneToValue(num);
       std::cout << num << std::endl;
    
       // print 1 (addOneToRef() changes the value of num)
       addOneToRef(num);
       std::cout << num << std::endl;
    }
    

    @crashmstr’s comment reminded me that I should say how they’re different from pointers. Wikipedia does a better job that I could though:

    • It is not possible to refer directly to a reference object after it is defined; any occurrence of its name refers directly to the object it references.
    • Once a reference is created, it cannot be later made to reference another object; it cannot be reseated. This is often done with pointers.
    • References cannot be null, whereas pointers can; every reference refers to some object, although it may or may not be valid.
    • References cannot be uninitialized. Because it is impossible to reinitialize a reference, they must be initialized as soon as they are created. In particular, local and global variables must be initialized where they are defined, and references which are data members of class instances must be initialized in the initializer list of the class’s constructor.
    • Most compilers will support a null reference without much complaint, crashing only if you try to use the reference in some way.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code works fine: typedef struct node_s { void *data; struct node_s *next;
When compiling the following code: void DoSomething(int Numbers[]) { int SomeArray[] = Numbers; }
I am trying to save images using the following code: - (void)writeData{ if(cacheFileName==nil) return;
I am trying to load a new view with the following code - (void)tableView:(UITableView
I have the following code: public void BeginConvert(object data) { ConverterData cObject = (ConverterData)data;
Consider the following code: void Handler(object o, EventArgs e) { // I swear o
I have the following code: void foo() { vector<double> v(100,1); // line 1 //
I have a UITableView with the following code: - (void)viewDidLoad { [super viewDidLoad]; parser
I have following code: private void ProcessQueue() { foreach (MessageQueueItem item in GetNextQueuedItem()) PerformAction(item);
I have the following code: public void post(String message) { final String mess =

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.