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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:26:49+00:00 2026-06-16T02:26:49+00:00

I am having a problem with the following code. I need to search first

  • 0

I am having a problem with the following code. I need to search first the record then delete it:

It always delete the last record. Even if I want to delete the first any rcord in the middle

string NameForSearch1;

                     cout<<"Enter Your Friend's Name:      "<<endl;
                     cin>>NameForSearch1;

                     tempRec->namePerson=NameForSearch1;

                     if (tempRec==firstRec){//delete the head

                                      tempRec->next=firstRec;
                                      firstRec=tempRec->next;
                                      delete tempRec;
                                      DisplayRec();
                                      }

                     else if (tempRec->next==NULL ){//delete the last record

                                      tempRec2=firstRec->next;
                                      while(tempRec2->next!=tempRec){
                                            tempRec2 = tempRec2->next;
                                      }
                                      tempRec2->next=NULL;                                         
                                      delete tempRec;


                                      }
                     else {
                          //delete anyrecord
                                          tempRec2=firstRec->next;
                                          while(tempRec2->next!=tempRec){
                                                                         tempRec2 = tempRec2->next;
                                                                         }             
                                          tempRec2->next=tempRec->next;
                                          delete tempRec;

                                          }
  • 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-16T02:26:50+00:00Added an answer on June 16, 2026 at 2:26 am

    After hours of debugging, I am finally able to get the right code:

    string NameForSearch1;
    
                         cout<<"Enter Your Friend's Name:      "<<endl;
                         cin>>NameForSearch1;
    
                         tempRec=firstRec;
    
                         if (tempRec->namePerson==NameForSearch1){//delete the head
    
                                          firstRec=tempRec->next;
                                          delete tempRec;
                                          DisplayRec();
                                          }
    
                         else 
                         {
                              while (tempRec!=NULL && tempRec->namePerson!=NameForSearch1){
                                                   tempRec2=tempRec;
                                                   tempRec=tempRec->next;
                                           }
    
                                           if (tempRec==NULL)
                                           {
                                                             cout<<"NO RECORD FOUND";
                                           }
                                           else if (tempRec->namePerson==NameForSearch1)
                                           {
                                                tempRec2->next=tempRec->next;
                                                delete tempRec;     
                                            }
                           }               
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problem with the following code, I need to do some modification
I'm having a problem with the following code foreach ($ex in (foo, bar, baz))
I'm having a problem with the following code snippet: <!DOCTYPE html> <html> <head> <title>Hangman</title>
The following code is having some problem with the jQuery. <script type="text/javascript"> $(window).load(function() {
I'm having a problem getting a change event to register with the following code:
I'm having a problem with TRY...CATCH blocks. Can someone explain why the following code
I'm having a problem with image scaling. When I use the following code to
I am having a little problem how can I turn the following code into
I'm having a bit of a problem with the following code. I've seen tons
I'm having a strange problem. I have the following code: dbg(condwait: timeout = %d,

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.