ورود

View Full Version : مبتدی: سوال : برنامه حذف یک گره از لیست پس از یک گره نامعلوم



5hahab
جمعه 01 خرداد 1394, 15:17 عصر
با سلام
یه سوال ساختمان داده داشتم که سوالش اینه
برنامه ای بنویسید برای حذف یک گره از لیست پس از یک گره نامعلوم
برنامه پایین رو واسش نوشتم فقط نمیدونم درست نوشتم یا نه ممنون میشم بگید درست نوشتم یا نه


/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#include <iostream>
#include <cstdlib>
using namespace std;
struct node{
int data;
node* next;};
class linkedlist{
private:
node* front;
public:
int Delete(node* n);
void show();
};
void linkedlist::show(){
cout<<"elements:";
node* cur=front;
while(cur != front){
cout<<cur->data<<',';
cur=cur->next;
}
}
int linkedlist::Delete(node* n){
if((front== NULL) || (n == NULL) || (n->next == NULL))
return -1;
node* d;
if(front->next==NULL){
d=front;
front=NULL;
}
else{
node* r;
r = n->next;
n->next = r->next;
}
}
int main()
{
return 0;
}

rahnema1
شنبه 02 خرداد 1394, 09:01 صبح
سلام
اینجور اصلاح کردم

void linkedlist::Delete(node*& n){
//....
node* r = n->next->next;
delete n->next;
n->next = r;
//...
}