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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:16:50+00:00 2026-05-27T03:16:50+00:00

After a lot of effort, I’ve managed to piece together a function that deletes

  • 0

After a lot of effort, I’ve managed to piece together a function that deletes some node from my linked list. But, out of sheer interest, I would like to find out how you can go about deleting the first node from the list, i.e. the head.

My program asks for a letter to delete, so for example.
Hello is stored in the list, the user inputs H for deletion, so that now the list is ello
At the moment with my code, the program crashes obviously as if H is deleted, there is no head, and the program doesn’t know where to go to look for the list.

Below is my current implementation, any clues or hints on how to modify this code( I would like to keep it similar to how I have) to allow Head Node Deletion would be much appreciated!.

EDIT: In response to below

FullList DeleteNode(FullList temp, char c) {
FullList remember;
FullList ptr;
while (temp.head->c != c) {
    remember.head = temp.head;
    temp.head = temp.head->next;
}
ptr.head = temp.head->next;
free(temp.head);
remember.head->next = ptr.head;
return temp;
}

int main(void) {
FullList List;
char c, s;
List.head = NULL;

while ((c=getchar()) != '.') {
    List = addToEnd(List, c);
}
scanf(" %c", &s);
List = DeleteNode(List, s);
while (List.head != NULL) {
    printf("%c", List.head->c);
    List.head = List.head->next;
}
return 0;
}

typedef struct List {
 char c;
 struct List *next;
}List;

typedef struct {
 List *head;
 List *tail;
}FullList;

 List *insertList(char c, List *t1) {
  List *t = (List*)calloc(1, sizeof(List));
  t->c = c ;
  t->next = t1;
 return t;
 }

FullList addToEnd(FullList c, char element) {
 if (c.head == NULL) { 
    c.head = c.tail = insertList(element, NULL);
 }else {
    c.tail->next = insertList(element, NULL);
    c.tail = c.tail->next;
 }
 return c;
} 

void DeleteNode(FullList temp, char c) {
 FullList remember;
 FullList ptr;
 while (temp.head->c != c) {
    remember.head = temp.head;
    temp.head = temp.head->next;
 } 
 ptr.head = temp.head->next;
 free(temp.head);
 remember.head->next = ptr.head;
} 


int main(void) {
 FullList List;
 char c, s;
 List.head = NULL;

 while ((c=getchar()) != '.') {
    List = addToEnd(List, c);
 }
 scanf(" %c", &s);
 DeleteNode(List, s);
 while (List.head != NULL) {
    printf("%c", List.head->c);
    List.head = List.head->next;
 }
 return 0;
}
  • 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-27T03:16:51+00:00Added an answer on May 27, 2026 at 3:16 am

    You can’t do it without changing your existing code.

    You’re passing your FullList struct to your DeleteNode() function. This means that any changes to that struct are not visible back in main – the function is getting a copy of it.

    You would need to change DeleteNode() to accept a pointer:

    void DeleteNode(FullList *temp, char c)
    

    Then when calling it main() you would do:

    DeleteNode(&List, s);
    

    By doing this, you can change the value of temp->head in your function and it will be visible back in main()

    temp->head = temp->head->next;
    

    Edit: The logic you’ll need is:

    • Check to see if temp->head->c == c
    • If yes, replace temp->head with temp->head->next
    • else assign temp->head to a temp pointer *previous. Assign temp->head->next to a pointer *current. Loop through the list, moving both pointers. When you find a match in current->c, assign current->next to previous->next and free() the current node.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I didn't know that installing ruby is such a pain After lot of trouble
After read a lot about ball physics, watch some examples and few days of
After doing some research on the subject, I've been experimenting a lot with patterns
An exploratory question, here. After some reading, I'm getting a sinking feeling that WCF's
After really a lot of efforts i have managed to get my php Zend
After some work, I managed to get HipHop up and running on my server.
After lot of struggle and googling finally I have managed to develop one dashboard
After a lot of investigations with valgrind, I've made the conclusion that std::vector makes
After a lot of experiments, my team concluded that working with hijacked files in
After lot of research and working for days, I really need some guidance here.

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.