Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- struct warr_entry{
- double var;
- warr_entry* next;
- warr_entry* prev;
- };
- class warr{
- public:
- warr(){
- m_head.next=NULL;
- m_head.prev=NULL;
- m_head.var=0;
- }
- warr_entry get(int idx){
- warr_entry *c=&m_head;
- int i=0;
- while(c->next!=NULL&&i!=idx){
- c=c->next;
- i++;
- }
- return *c;
- }
- int get(warr_entry e){
- warr_entry *c=&m_head;
- int i=0;
- while(c->next!=NULL&&c!=&e){
- i++;
- c=c->next;
- }
- return i;
- }
- warr_entry& operator[] (const int nIndex){
- return get(nIndex);
- };
- void add(double v){
- warr_entry *a=new warr_entry;
- a->next=NULL;
- warr_entry *l=last();
- l->var=v;
- l->next=a;
- a->prev=a;
- };
- int rem(int idx){
- warr_entry *c = &m_head;
- int i=0;
- while(c->next!=NULL && i!=idx){
- i++;
- c=c->next;
- }
- c->prev->next=c->next;
- delete &c;
- return i;
- };
- warr_entry first(){
- return m_head;
- }
- warr_entry *last(){
- warr_entry *c=&m_head;
- while(c->next!=NULL){
- c=c->next;
- }
- return c;
- };
- int size(){
- int cs=0;
- warr_entry *c=&m_head;
- while(c->next != NULL){
- cs++;
- c=c->next;
- }
- return cs;
- };
- void printall(){
- warr_entry* e=&m_head;
- while(e->next != NULL){
- cout<<e->var<<endl;
- e=e->next;
- }
- }
- private:
- warr_entry m_head;
- };
- int main(int argc, _TCHAR* argv[])
- {
- warr w;
- w.add(10293);
- w.add(212);
- w.add(1.1021);
- cout<<w.get(1).var<<endl;
- cout<<w[1].var<<endl;
- w.printall();
- cout<<w.size()<<endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement