161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/*--------------------------------------------------------------------------
261e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiCopyright (c) 2010, The Linux Foundation. All rights reserved.
361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
461e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiRedistribution and use in source and binary forms, with or without
561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletimodification, are permitted provided that the following conditions are met:
661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    * Redistributions of source code must retain the above copyright
761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti      notice, this list of conditions and the following disclaimer.
861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    * Redistributions in binary form must reproduce the above copyright
961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti      notice, this list of conditions and the following disclaimer in the
1061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti      documentation and/or other materials provided with the distribution.
1161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    * Neither the name of The Linux Foundation nor
1261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti      the names of its contributors may be used to endorse or promote
1361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti      products derived from this software without specific prior written
1461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti      permission.
1561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
1661e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1761e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1861e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiIMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1961e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiNON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
2061e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiCONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2161e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiEXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2261e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiPROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2361e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2461e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiWHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2561e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2661e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti--------------------------------------------------------------------------*/
2861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#ifndef _MAP_H_
2961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define _MAP_H_
3061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
3161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <stdio.h>
3261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiusing namespace std;
3361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
3461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitemplate <typename T,typename T2>
3561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleticlass Map
3661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{
3761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    struct node
3861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    {
3961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        T    data;
4061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        T2   data2;
4161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        node* prev;
4261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        node* next;
4361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        node(T t, T2 t2,node* p, node* n) :
4461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti             data(t), data2(t2), prev(p), next(n) {}
4561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    };
4661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    node* head;
4761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    node* tail;
4861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    node* tmp;
4961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    unsigned size_of_list;
5061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    static Map<T,T2> *m_self;
5161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletipublic:
5261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    Map() : head( NULL ), tail ( NULL ),tmp(head),size_of_list(0) {}
5361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    bool empty() const { return ( !head || !tail ); }
5461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    operator bool() const { return !empty(); }
5561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    void insert(T,T2);
5661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    void show();
5761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    int  size();
5861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    T2 find(T); // Return VALUE
5961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    T find_ele(T);// Check if the KEY is present or not
6061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    T2 begin(); //give the first ele
6161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    bool erase(T);
6261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    bool eraseall();
6361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    bool isempty();
6461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    ~Map()
6561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    {
6661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        while(head)
6761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        {
6861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            node* temp(head);
6961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            head=head->next;
7061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            size_of_list--;
7161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            delete temp;
7261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        }
7361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    }
7461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti};
7561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
7661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitemplate <typename T,typename T2>
7761e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiT2 Map<T,T2>::find(T d1)
7861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{
7961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    tmp = head;
8061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    while(tmp)
8161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    {
8261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        if(tmp->data == d1)
8361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        {
8461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            return tmp->data2;
8561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        }
8661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        tmp = tmp->next;
8761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    }
8861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    return 0;
8961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti}
9061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
9161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitemplate <typename T,typename T2>
9261e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiT Map<T,T2>::find_ele(T d1)
9361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{
9461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    tmp = head;
9561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    while(tmp)
9661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    {
9761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        if(tmp->data == d1)
9861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        {
9961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            return tmp->data;
10061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        }
10161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        tmp = tmp->next;
10261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    }
10361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    return 0;
10461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti}
10561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
10661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitemplate <typename T,typename T2>
10761e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiT2 Map<T,T2>::begin()
10861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{
10961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    tmp = head;
11061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    if(tmp)
11161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    {
11261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        return (tmp->data2);
11361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    }
11461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    return 0;
11561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti}
11661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
11761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitemplate <typename T,typename T2>
11861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletivoid Map<T,T2>::show()
11961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{
12061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    tmp = head;
12161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    while(tmp)
12261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    {
12361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        printf("%d-->%d\n",tmp->data,tmp->data2);
12461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        tmp = tmp->next;
12561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    }
12661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti}
12761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
12861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitemplate <typename T,typename T2>
12961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint Map<T,T2>::size()
13061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{
13161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    int count =0;
13261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    tmp = head;
13361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    while(tmp)
13461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    {
13561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        tmp = tmp->next;
13661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        count++;
13761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    }
13861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    return count;
13961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti}
14061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
14161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitemplate <typename T,typename T2>
14261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletivoid Map<T,T2>::insert(T data, T2 data2)
14361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{
14461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    tail = new node(data, data2,tail, NULL);
14561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    if( tail->prev )
14661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        tail->prev->next = tail;
14761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
14861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    if( empty() )
14961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    {
15061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        head = tail;
15161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        tmp=head;
15261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    }
15361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    tmp = head;
15461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    size_of_list++;
15561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti}
15661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
15761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitemplate <typename T,typename T2>
15861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletibool Map<T,T2>::erase(T d)
15961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{
16061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    bool found = false;
16161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    tmp = head;
16261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    node* prevnode = tmp;
16361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    node *tempnode;
16461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
16561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    while(tmp)
16661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    {
16761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        if((head == tail) && (head->data == d))
16861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        {
16961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti           found = true;
17061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti           tempnode = head;
17161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti           head = tail = NULL;
17261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti           delete tempnode;
17361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti           break;
17461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        }
17561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        if((tmp ==head) && (tmp->data ==d))
17661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        {
17761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            found = true;
17861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            tempnode = tmp;
17961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            tmp = tmp->next;
18061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            tmp->prev = NULL;
18161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            head = tmp;
18261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            tempnode->next = NULL;
18361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            delete tempnode;
18461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            break;
18561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        }
18661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        if((tmp == tail) && (tmp->data ==d))
18761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        {
18861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            found = true;
18961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            tempnode = tmp;
19061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            prevnode->next = NULL;
19161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            tmp->prev = NULL;
19261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            tail = prevnode;
19361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            delete tempnode;
19461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            break;
19561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        }
19661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        if(tmp->data == d)
19761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        {
19861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            found = true;
19961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            prevnode->next = tmp->next;
20061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            tmp->next->prev = prevnode->next;
20161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            tempnode = tmp;
20261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            //tmp = tmp->next;
20361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            delete tempnode;
20461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti            break;
20561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        }
20661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        prevnode = tmp;
20761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti        tmp = tmp->next;
20861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    }
20961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    if(found)size_of_list--;
21061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    return found;
21161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti}
21261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
21361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitemplate <typename T,typename T2>
21461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletibool Map<T,T2>::eraseall()
21561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{
21661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    // Be careful while using this method
21761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    // it not only removes the node but FREES(not delete) the allocated
21861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    // memory.
21961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    node *tempnode;
22061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    tmp = head;
22161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    while(head)
22261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    {
22361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti       tempnode = head;
22461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti       head = head->next;
22561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti       tempnode->next = NULL;
22661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti       if(tempnode->data)
22761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti           free(tempnode->data);
22861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti       if(tempnode->data2)
22961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti           free(tempnode->data2);
23061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti           delete tempnode;
23161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    }
23261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    tail = head = NULL;
23361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    return true;
23461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti}
23561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
23661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
23761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitemplate <typename T,typename T2>
23861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletibool Map<T,T2>::isempty()
23961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{
24061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    if(!size_of_list) return true;
24161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti    else return false;
24261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti}
24361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti
24461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#endif // _MAP_H_
245