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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:36:07+00:00 2026-06-15T07:36:07+00:00

I am currently writing a program that has a function that needs to delete

  • 0

I am currently writing a program that has a function that needs to delete a node based on its value.

I have tried and tried to figure it out.

All I have so far is the function signature:

NODE* delete_node(NODE * ptr, int n, int *success_flag)

My linked list as the follow structure:

/* declaration of structure */
typedef struct node
{
  int data;
  struct node *next;
} NODE;

Heres some of the code I already have regarding another concerns:

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

/* declaration of structure */
typedef struct node
{
  int data;
  struct node *next;
} NODE;

/* declaration of functions */
NODE* insert_node(NODE *ptr, NODE *new);
NODE* find_node(NODE *ptr, int n);
NODE* delete_node(NODE *ptr, int n, int *success_flag_ptr);
void print_backward_iteration(NODE *ptr);
void print_backward_recursion(NODE *ptr);

int main(int argc, char *argv[])
{
  int choice, x, flag_success;
  NODE *ptr, *new, *result;

  ptr = NULL;

  do
    {

      printf("\n1.\tInsert Integer into linked list\n");
      printf("2.\tFind integer in linked list\n");
      printf("3.\tDelete integer from linked list\n");
      printf("4.\tPrint out integers backward using the iterative strategy\n");
      printf("5.\tPrint out integers backward using the recursive strategy\n");
      printf("6.\tQuit\n");
      printf("\nEnter 1,2,3,4,5, or 6: ");
      scanf("%d", &choice);

      switch(choice)
    {
    case 1:

      printf("\nPlease enter an integer: ");
      scanf("%d", &x);
      new = (NODE *)malloc(sizeof(NODE));
      new->data = x;
      ptr = insert_node(ptr, new);
      printf("\nNode Inserted with value of %d.\n", ptr->data);
      break;

    case 2:

      printf("\nPlease enter an integer: ");
      scanf("%d", &x);
      result = find_node(ptr, x);

      if (result == NULL)
        {
          printf("\nValue could not be found.\n");
        }
      else
        {
          printf("\nValue %d was found.\n", x);
        }

      break;

    case 3:
      printf("\nPlease enter an integer: ");
      scanf("%d", &x);
      ptr = delete_node(ptr, x, &flag_success);

        if (result == NULL)
        {
          printf("\nValue could not be found.\n");
        }
      else
        {
          printf("\nValue %d was deleted.\n", x);
        }

      break;

    case 4:

      print_backward_iteration(ptr);
      break;

    case 5:

      printf("\n");
      print_backward_recursion(ptr);
      printf("\n");

      break;

    case 6:
      printf("\nThank you for using this program.\n");
    break;

    default:
      printf("\nInvalid Choice. Please try again.\n");
      break;

    }
    }
  while (choice != 6);

  printf("\n*** End of Program ***\n");
  return 0;
}

/* definition of function insert_node */
NODE* insert_node(NODE *ptr, NODE *new)
{

 new -> next = ptr;
 return new;

}

/* definition of function find_node */
NODE* find_node(NODE *ptr, int n)
{

  while (ptr != NULL)
    {
      if (ptr->data == n)  
    {
      return ptr;
    }
      else
    {
      ptr = ptr->next;
    }
    }
  return NULL;
  }

/* definition of function print_backward_iteration */
void print_backward_iteration(NODE *ptr)
{
  NODE *last, *current;

  last = NULL;

  printf("\n");

  while (ptr != last)
    {
      current = ptr;

      while (current != last)
    {
      current =  current -> next;
    }

      printf("%d  ", current -> data);
      last = current -> next;
    }

    printf("\n");

}

/* definition of function print_backward_recursion */
void print_backward_recursion(NODE *ptr)
{
  NODE *last, *current;

  last = NULL;

  while (ptr != last)
      {
    current = ptr;
    printf("%d  ", current -> data);
    print_backward_recursion(current -> next);
    last = current;
      }

}
  • 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-15T07:36:08+00:00Added an answer on June 15, 2026 at 7:36 am

    You have to do something like this:

    NODE* delete_node(NODE * ptr, int n, int *success_flag)
    {
       Node *aux = NULL;
    
       if(ptr == NULL) // this means that theres is no 'n' in this linked list
       {
        *success_flag = 0;  // means no value found
        return NULL;
       }
       if(ptr-> n == n){     // if this is the value you want
          aux = ptr->next;   // aux will point to the remaining list
          free(ptr);         // free the actual node
          *success_flag = 1; // mark as success 
          return aux;        // return the pointer to the remaining list
        }
       else // lets see the remaining nodes 
          ptr->next = delete_node(ptr->next,n,success_flag); 
    
      return ptr;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently writing a program that has a function that prints a linked
I have the following problem: I am writing a C++ program that has to
I'm currently writing a program that has debug output strewn throughout it. This is
I'm currently writing a java program that requires some Data to run. The data
I am currently writing a program using Weka that builds a model (using one
I am writing a program that generates excel reports, currently using the Microsoft.Interop.Excel reference.
Backgorund I am currently writing a program that allows a user to select a
I have a program that has items with 3 attributes. Name(String) : Count(String) :
I'm currently writing a program that uses ; as a seperator and extracts the
I am currently writing a C program that requires frequent comparisons of string lengths

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.