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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:37:06+00:00 2026-06-04T12:37:06+00:00

As always being this problem comes from a book’s exercises. Neither I am not

  • 0

As always being this problem comes from a book’s exercises.
Neither I am not studying data structures, nor the book is about that.
But, there is a chapter that is “Dynamic Data Structures”. I’ve already finished this chapter.

But, I have problem with insertion. In my opinion, my function works correctly, except that it makes duplicate nodes.

I made a precaution for that but it doesn’t work. Anyway, please forgive me because of my silly mistakes.
OK, Here my structure types for name lists.

typedef struct name_node_s {
char name[11];
struct name_node_s *restp;
}name_node_t;

typedef struct {
    name_node_t *headp;
    int size;
}name_list_t;

place_first function:

name_node_t *
place_first(name_list_t *old_listp, char name[11])
{
    name_list_t *new_listp, *cur_listp;
    name_node_t *new_nodep, *temp_nodep;
    temp_nodep = (name_node_t *)malloc(sizeof (name_node_t));
    new_listp = (name_list_t *)malloc(sizeof (name_list_t));
    cur_listp = (name_list_t *)malloc(sizeof (name_list_t));
    new_nodep = (name_node_t *)malloc(sizeof (name_node_t));
    cur_listp->headp = old_listp->headp;
    temp_nodep = old_listp->headp;
    new_listp = old_listp;
    if ( old_listp->headp->name != name ){ // My first precaution for duplication
        while(cur_listp->headp->restp != NULL && cur_listp->headp->name != name) // My second precaution for duplication
        {
            if (old_listp->headp == NULL){
                strcpy(new_listp->headp->name, name);
                new_listp->headp->restp = NULL;
            }
            else if (old_listp->headp->name != name) { // Third one.
                strcpy(new_nodep->name, name);
                new_nodep->restp = NULL;
                new_listp->headp = new_nodep;
                new_listp->headp->restp = temp_nodep;
                ++(old_listp->size);
            }
        cur_listp->headp = cur_listp->headp->restp;
        }
    }
    else{
        new_listp->headp = old_listp->headp;
    }
    return(new_listp->headp);
}

I call that function like this;

listp->headp = place_first(listp, "Mustafa");
listp->headp = place_first(listp, "Mustafa");

My output like this:
__Mustafa
__Mustafa
__Ataturk
__Ali
__Eisenhower
__Kennedy
Thanks for advance…

  • 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-04T12:37:08+00:00Added an answer on June 4, 2026 at 12:37 pm

    Here

    if ( old_listp->headp->name != name ){
    

    you are comparing pointers, not the contents, you want

    if (strcmp(old_listp->headp->name,name)){
    

    The same applies to the other checks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with flash content in IE7 being always over the menu
I've never had a problem with any changes to the db not being reflected
I always hear that Java being open-source is a big benefit, but I fail
I always wondered how to document a method that overrides a message from a
I always hear using global variables are dangerous. Does this apply to Drupal? Take
I'm working with a SelectList, and populating it with the data from a table.
I have this problem: I have a collection of small files that are about
I am trying to gather data from multiple sources on an Ubuntu 10.10 machine
I'm working on a signup page in CodeIgniter. The problem is, my post data
Man being developer is great but days like this make you want to become

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.