You are on page 1of 3

55 #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; }

You might also like