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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:44:24+00:00 2026-06-15T13:44:24+00:00

void removeDuplicateWithHashtable(LinkedListElement<char> *head) { LinkedListElement<char> *runner = head; LinkedListElement<char> *previous = nullptr; hash_map<char, bool>

  • 0
void removeDuplicateWithHashtable(LinkedListElement<char> *head)
{
    LinkedListElement<char> *runner = head;
    LinkedListElement<char> *previous = nullptr;
    hash_map<char, bool> record;
    while (runner) {
        if (record.count(runner->Data) == 0) {
            pair<char, bool> item(runner->Data,true);
            record.insert(item);
        }else
        {
            free(runner);
            previous->Next = runner->Next;
        }
        previous=runner;
        runner=runner->Next;
    }
}

Initially I thought there would be an error. Because in free(runner), if i free the memory, i can not access runner->Next.
But GCC compiler ran successfully.

Actually if i change free to delete runner, it is also correct.
can i ask the reason may be free or delete just tell you the memory is available no actually clear data inside, so you can also access Next.
And can i ask how to improve it?

  • 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-15T13:44:25+00:00Added an answer on June 15, 2026 at 1:44 pm

    It is not a compilation error but the problem (undefined behaviour) will manifest itself at runtime. If you choose to call free on unallocated memory the compiler will not stop you.

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

Sidebar

Related Questions

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { xmlParseChunk(context, (const char *)[data bytes], [data length], 0);
void test() { unsigned char c; c = (~0)>>1 ; printf(c is %u\n,c); }
void SaveFiles(out XElement Attachments) { Attachments = null; if (Uploader1.UploadedFiles.Count() > 0) { Attachments
void say(char msg[]) { // using pointer to print out the first char of
void AFCQueue::ExtractValuesSecComplex(int startIndex, int endIndex,int helperIndex) { int size = 0,i,index; TimeType min_timestamp; bool
void return_input (void) { char array[30]; gets (array); printf(%s\n, array); } After compiling it
void max_min(sqlite3 *db) { //call back********* int i, ncols; sqlite3_stmt *stmt; char *sql; const
void expand_combinations(const char *remaining_string, string const & s, int rema in_depth) { if(remain_depth==0) {
void reverse_string(char* string, int str_size) { char tmp; int i = 0; int j
void dataGridView1_DragDrop(object sender, DragEventArgs e) { object data = e.Data.GetData(typeof(string)); MessageBox.Show(e.X + + e.Y

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.