A uri ip : add URI and IP string pairs to the link list.
D uri : delete the URI and its associated IP from the link list.
U uri : given a URI find the IP address from the link list.
I ip : given an IP find the URI from the link list.
N : print out the number of items in the link list then
a line feed.
There may be several commands on the command line, for example-
- "A www.x.y 1.2.3.4 A www.a.b 7.8.9.10 N"
response "2".
- "A www.x.y 1.2.3.4 A www.a.b 7.8.9.10 U www.a.b"
response "7.8.9.10".
- "A www.x.y 1.2.3.4 A www.a.b 7.8.9.10 U www.a.B"
response "nil".
- "A www.x.y 1.2.3.4 A www.a.b 7.8.9.10 u www.a.B"
response "command error".
this is basic code below...but it doesnt do exectly what is require...please help///
#include <iostream>
#include <cstdlib>
using namespace std;
class linklist
{
private:
struct node
{
char *ip;
char *uri;
node *link;
}*p;
public:
linklist();
void append( char *ip,char *uri );
void del( char *ip );
void display(char *ip,char *uri);
int count();
~linklist();
};
linklist::linklist()
{
p=NULL;
}
void linklist::append(char *ip,char *uri)
{
node *q,*t;
if( p == NULL )
{
p = new node;
p->ip = ip;
p->uri=uri;
p->link = NULL;
}
else
{
q = p;
while( q->link != NULL )
q = q->link;
t = new node;
t->ip = ip;
t->uri=uri;
t->link = NULL;
q->link = t;
}
}
void linklist::del( char *ip )
{
node *q,*r;
q = p;
if( q->ip == ip )
{
p = q->link;
delete q;
return;
}
r = q;
while( q!=NULL )
{
if( q->ip == ip )
{
r->link = q->link;
delete q;
return;
}
r = q;
q = q->link;
}
cout<<"\nElement "<<ip<<" not Found.";
}
void linklist::display(char *ip,char *uri)
{
node *q;
cout<<endl;
for( q = p; q != NULL; q = q->link )
cout<<endl<<q->ip<<" "<<q->uri<<endl;
}
int linklist::count()
{
node *q;
int c=0;
for( q=p; q != NULL; q = q->link )
c++;
return c;
}
linklist::~linklist()
{
node *q;
if( p == NULL )
return;
while( p != NULL )
{
q = p->link;
delete p;
p = q;
}
}
int main(int argc,char * argv[])
{
for(int i=1; i<argc; i++) {
char letter = argv[i][0];
linklist ll;
cout<<"No. of elements = "<<ll.count();
ll.append(argv[i++],argv[i++]);
ll.display(argv[i++],argv[i++]);
cout<<"\nNo. of elements = "<<ll.count();
ll.del(argv[i++]);
}
system ("pause");
return 0;
}
i really need it...

New Topic/Question
Reply




MultiQuote







|