السلام عليكم
لو سمحتم احتاج مساعدتكم في كتابة برنامج يحتوي على خوارزمية "list" يقوم بإدخال 3اسماء لطلاب وارقامهم
انا قمت بكتابة الخوارزمية لكن واجهت مشكلة في main البرنامج الأساسي لم اعرف كيف استدعي الدالة التي تقوم بإدخال اسم الطالب ورقمه ثم طلب مني ابحث عن اسم احمد واستبدله بإسم علي هل استخدم if في هذا المطلوب؟
#include <iostream>
using namespace std;
class linklist
{
public:
class node
{public:
int data;
node *next;
char name;
}*p;
linklist()
{
p=NULL;
}
void append(int num,char sname)
{
node *q,*t;
if( p == NULL )
{
p = new node;
p->data = num;
p->name=sname;
p->next = NULL;
}
else
{
q = p;
while( q->next != NULL )
q = q->next;
t = new node;
t->data = num;
t->name=sname;
t->next = NULL;
q->next = t;
}
}
void add_as_first(int num,char sname)
{
node *q;
q = new node;
q->data = num;
p->name=sname;
q->next = p;
p = q;
}
void addafter( int c, int num,char sname)
{
node *q,*t;
int i;
for(i=0,q=p;i<c;i++)
{
q = q->next;
if( q == NULL )
{
cout<<"\nThere are less than "<<c<<" elements.";
return;
}
}
t = new node;
t->data = num;
t->name=sname;
t->next = q->next;
q->next = t;
}
void del( int num )
{
node *q,*r;
q = p;
if( q->data == num )
{
p = q->next;
delete q;
return;
}
r = q;
while( q!=NULL )
{
if( q->data == num )
{
r->next = q->next;
delete q;
return;
}
r = q;
q = q->next;
}
cout<<"\nElement "<<num<<" not Found.";
}
void Traverse()
{
node *q;
cout<<endl;
for( q = p ; q != NULL ; q = q->next )
cout<<endl<<q->data;
}
int count()
{
node *q;
int c=0;
for( q=p ; q != NULL ; q = q->next )
c++;
return c;
}
~linklist()
{
node *q;
if( p == NULL )
return;
while( p != NULL )
{
q = p->next;
delete p;
p = q;
}
}};
int main()
{
char a[3];
int b[3];
int i;
linklist ll;
for(i=0;i<2;i++)
{
ll.add_as_first(b,a);
}
for(i=0;i<2;i++)
ll.Traverse()
int h;
cin>>h;
}وشكرا جزيلا مقدما