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

  • Home
  • SEARCH
  • 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 5961321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:56:54+00:00 2026-05-22T18:56:54+00:00

ma fellow geek, i’ve created single linked list algorithm, but i didnt see it

  • 0

ma fellow geek,
i’ve created single linked list algorithm, but i didnt see it work properly :

#include <stdio.h>
#include <stdlib.h>

/*
 * 
 */
  typedef struct _data_konfirm
    {
        char *id;
        char *buff;
        int v;

        struct _data_konfirm *next;
    }data_konfirm;

 void data_add(data_konfirm **data,char *id,char *buff,int v)
{
    data_konfirm *tmp = (data_konfirm*)malloc(sizeof(data_konfirm));
    tmp->id             = strdup(id);
    tmp->buff           = strdup(buff);
    tmp->v = v;

    tmp->next = *data;
    *data = tmp;    
}

void data_destroy(data_konfirm **data)
{
        data_konfirm *b = *data;
        free(b->id);
        free(b->buff);
        free(b);
}

void data_del(data_konfirm **data,char *id)
{


    data_konfirm *tmp = *data, *b = NULL;

    if(!strcmp(tmp->id,id))
    {
        b = tmp;
        tmp = tmp->next;
        data_destroy(&b);              
        return;
    }


    while(tmp->next->next != NULL)
    {
        if(!strcmp(tmp->next->id,id))
        {
            b = tmp->next;
            tmp->next = b->next;
            data_destroy(&b);

            return;
        }

        tmp = tmp->next;
    }

    if(!strcmp(tmp->next->id,id))
    {
        b = tmp->next;
        data_destroy(&b);
        tmp->next = NULL;
        return;        
    }


}

void inform_show_all(data_konfirm **data)
{        
    data_konfirm *tmp = *data;
    int i = 0;
    while(tmp)
    {
        printf("id              -> %s\n",tmp->id);
        printf("buff            -> %s\n",tmp->buff);        
        i++;
        tmp = tmp->next;
    }

    printf("jumlah data : %d\n",i);
}


int main(int argc, char** argv) {
    data_konfirm *a = NULL;

    data_add(&a,"1","silit",2);
    data_del(&a,"1");
    data_add(&a,"2","wwww",1);
    data_add(&a,"3","zzz",2);
    data_add(&a,"4","huaaa",2);

    data_del(&a,"3");

    inform_show_all(&a);
    return (EXIT_SUCCESS);
}

if i run these code, the loop will never end, whats wrong then ?

thank in 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-05-22T18:56:54+00:00Added an answer on May 22, 2026 at 6:56 pm

    In function data_del substitute

    b = tmp;
    tmp = tmp->next;
    

    with

    b = *data;
    *data = (*data)->next;
    

    Here is a picture of the situation:

    *data -> +---+           +---+
      tmp -> | | | -> ... -> | | |
        b -> +---+           +---+
    

    The statement tmp = tmp->next will not update the pointer *data.

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

Sidebar

Related Questions

Hello fellow Computer People! I could do this myself, but was just wondering if
Hey fellow Rail-ists, do know any equivalent of ActiveScaffold but being ORM agnostic or
Dear Fellow Android Developers! EDIT: Thank you all for your answers. I see from
Fellow coders, I have asked this question before but did not get a conclusive
fellow anthropoids and lily pads and paddlewheels! I'm developing a Windows desktop app in
Avast there fellow programmers! I have the following problem: I have two rectangles overlapping
I'm about to start (with fellow programmers) a programming & algorithms club in my
Many years ago I remember a fellow programmer counselling this: new Some::Class; # bad!
Here is an interesting piece of code that my fellow team members were just
Do you think Unit Tests are a good way to show your fellow programmers

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.