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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:57:07+00:00 2026-06-08T16:57:07+00:00

I’m trying to append two structures into one Ex. l1 = add(1, add(2, NULL));

  • 0

I’m trying to append two structures into one
Ex.

l1 = add(1, add(2, NULL));
l2 = add(3, add(4, NULL));
myappend(l1,l2) = add(1,add(2,add(3,add(4,NULL))))

I tried many other ways that I can think of… but it doesn’t work… can anyone help me out?

struct list_node {
   struct list_node * rest;
   int first;
};

list add(int in, list l) {
   list r = malloc(sizeof(struct list_node));
   r->first = in;
   r->rest = l;
   return r;
}
// My attempted solution;
list myappend(list l1,list l2){
   list k = malloc(sizeof(struct list_node));
   k=l2;
   k=add(l1,k);
   return k;
}
  • 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-08T16:57:09+00:00Added an answer on June 8, 2026 at 4:57 pm

    I guess the type list is struct list_node *. If you can define a type for list, you can define a type for list with a last point to the last node of the list, example:

    struct list {
        struct list_node *first;
        struct list_node *last;
    }
    void myappend(struct list *l1,struct list *l2){
       // check the argument here when needed.
    
       l1->last->rest = l2->first;
       l1->last = l2->last;
       free(l2);
    }
    

    If you want to keep the type list as struct list_node *, you should
    1) Ensure the last node(of a list)’s rest is NULL.
    2) Loop and find the last node of the fist list and do the merge(just link them).

    You can also use recursion code:

    list __add(struct list_node *first_node, list rest) { // split your list_add()
       first_node->rest = rest;
       return first_node
    }
    list add(int in, list l) {
       list r = malloc(sizeof(struct list_node));
       r->rest = NULL;
       r->first = in;
       return __add(r, l);
    }
    list myappend(list l1,list l2){
       if (l1)
           return __add(l1, myappend(l1->rest, l2));
       else
           return l2;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I know there's a lot of other questions out there that deal with this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.