Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* LL-NODE.h */
- #ifndef NODE_h
- #define NODE_h
- #include<iostream>
- using namespace std;
- class NODE
- {
- int id;
- string name;
- NODE* next;
- public:
- NODE(int,string);
- void show_node();
- void insert(NODE*&);
- NODE* move_next();
- ~NODE();
- };
- #endif
- /* LL-LL */
- class LL
- {
- NODE*hol;
- int size;
- public:
- void add_node(NODE*&);
- void show_all();
- LL();
- ~LL();
- };
- /* LL-NODE.cpp */
- #include"NODE.h"
- NODE::NODE(int x,string n)
- {
- id=x;
- name=n;
- next=NULL;
- cout<<"adding "<<x<<endl;
- }
- NODE:: ~NODE()
- {
- cout<<"Node "<<id<<" is being deleted"<<endl;
- }
- NODE* NODE::move_next()
- {
- return next;
- }
- void NODE::show_node()
- {
- cout<<"Node data:"<<id<< " Name " <<name<< endl;
- }
- void NODE::insert(NODE*& x)
- {
- x->next=this;
- }
- /* LL-LL.cpp */
- #include"NODE.h"
- #include"LL.h"
- LL::LL()
- {
- hol=NULL;
- size=0;
- }
- LL::~LL()
- {
- NODE* tem;
- while(hol!=NULL){
- tem=hol->move_next();
- delete hol;
- hol=tem;
- }
- }
- void LL::show_all()
- {
- NODE* t=hol;
- int i;
- for(i=0; i<size; i++)
- {
- t->show_node();
- t=t->move_next();
- }
- }
- void LL::add_node(NODE *&A)
- {
- hol->insert(A);
- hol=A;
- size++;
- }
- /* LL-LLtest */
- #include <iostream>
- #include <cstdlib>
- #include "NODE.h"
- #include "LL.h"
- using namespace std;
- class student:public NODE
- {
- double gpa;
- public:
- student(int x,string n,double g):NODE(x,n)
- {
- gpa=g;
- }
- ~student();
- };
- int main(int argc, char *argv[])
- {
- LL A;
- int i;
- NODE *t;
- for(i=1; i<argc; i+=3)
- {
- t = new student(atoi(argv[i]),argv[i+1],atof(argv[i+2]));
- A.add_node(t);
- }
- A.show_all();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement