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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:35:47+00:00 2026-06-18T09:35:47+00:00

Here is my code. The problem that I am getting is that I can’t

  • 0

Here is my code. The problem that I am getting is that I can’t make work the deleter part. I want to delete one element of the structure. Here is a basic structure that you add, search and delete elements that are added. Also the elements are sorted in increasing order.

#include <iostream>

using namespace std;

struct el {
    int key;
    el *next;
} *start;

void init();
void add(int n);
void list();
void search(int n); // ima za dopylvane
void deleter(int n);
void main() {
    init();
    int n, num;
    do {
        cout << "\n Menu\n";
        cout << "\n1 - Add element";
        cout << "\n2 - List elements";
        cout << "\n3 - Searching for element";
        cout << "\n4 - Delete element";
        cout << "\n5 - Exit";
        cout << "\n Your choice:";
        cin >> n;
        switch (n) {
            case 1:
                {
                    cout << "\n Input num:";
                    cin >> num;
                    add(num);
                    break;
                }
            case 2:
                {
                    list();
                    break;
                }
            case 3:
                {
                    cout << "\n Input num for searching:";
                    cin >> num;
                    search(num);
                    break;
                }
            case 4:
                {
                    cout << "\n Input num for deleting:";
                    cin >> num;
                    deleter(num);
                    break;
                }

        }
    }
    while (n != 5);
}
void list() {
    el *p = start;
    if (start) while (p) {
        cout << p->key << "  ";
        p = p->next;
    } else cout << "\n Empty list";
}
void init() {
    start = NULL;
}
void add(int n) {
    el *p = start;
    if (!start) {
        start = new el;
        start->key = n;
        start->next = NULL;
    } else {
        if (start->key > n) {
            start = new el;
            start->key = n;
            start->next = p;
        } else {
            el * q;
            while ((p->key < n) && (p->next)) {
                q = p;
                p = p->next;
            }
            if (p->key > n) {
                el *s;
                s = new el;
                s->key = n;
                s->next = p;
                q->next = s;
            } else {
                el *s;
                s = new el;
                s->key = n;
                s->next = NULL;
                p->next = s;
            }
        }

    }
}
void search(int n) {
    el *p = start;
    if (!start) cout << "\nEmpty list!";
    else while ((p->key != n) && (p-> next))
    p = p->next;
    if (p->key == n) cout << "\nYes!";
    else cout << "\nNo!";
}


void deleter(int n) {
    el *p = start;
    if (!start) cout << "Enfsad";
    else while ((p->key != n) && (p->next)) {
        n = start->key;
        start = start->next;
        delete p;
    }
}
  • 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-18T09:35:48+00:00Added an answer on June 18, 2026 at 9:35 am

    Your deleter function should be like this.

    void deleter (int n)
    {
        el *p = start;
        el *prev = p;
    
        if (!start)
        {
            cout<<"Enfsad";
        }
    
        if(start->key == n)
        {
            start = start->next;
            delete prev;
        }
        else
        {
            while (p)
            {
                if(p->key == n)
                {
                    prev->next = p->next;
                    p->next = NULL;
                    delete p; 
                    break;
                }
                prev = p;
                p = p->next;
            }
        }
    }
    

    Although I think you need to check how a good linked list should be.

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

Sidebar

Related Questions

Basically my problem is that i've adapted a piece of code found here http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1
Here is my code. The problem is that the information isn't being alerted. It
Here is my code: $('#right').load('textes.html #nicolas'); $('#right').load('textes.html #antoine'); The problem is that the content
Hi I have a code example available here: http://jsbin.com/oxoweh My problem is that I
Here is the code that cause me problem since few hours: TabItem newTab =
I am trying to solve this exponentiation problem . Here is the code that
Here is the smallest amount of code that clearly illustrates my problem: <html> <body>
Here is a JSFiddle that demonstrates the problem... http://jsfiddle.net/L2NBP/5/ For obvious reasons this code
my first question here! I have a problem with a piece of code that
So, here's the problem. I wrote a code that opens a div based on

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.