Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么使用visual c++;2010不显示堆[i]。左侧和堆[i]。右侧选项?_C++_Visual Studio 2010 - Fatal编程技术网

C++ 为什么使用visual c++;2010不显示堆[i]。左侧和堆[i]。右侧选项?

C++ 为什么使用visual c++;2010不显示堆[i]。左侧和堆[i]。右侧选项?,c++,visual-studio-2010,C++,Visual Studio 2010,下面是我的间隔堆实现,代码如下 #include <iostream> #include<algorithm> using namespace std; template <class T> class IntervalHeap; template <class T> class TwoElement { friend class IntervalHeap <T>; public: T left, ri

下面是我的间隔堆实现,代码如下

#include <iostream>
#include<algorithm>
using namespace std;
template <class T> class IntervalHeap;
template <class T>
class TwoElement
{
    friend  class IntervalHeap <T>;
public:
    T left,
        right;
    };
template<class T>
class IntervalHeap
{
public:
    IntervalHeap(int heapsize=10);
    ~IntervalHeap(){delete[] heap;}
    int size()const { return currentsize;}
    T Min()
    {
         if (currentsize==0)
            // throw OutOfBounds();
          return heap[1].left;
    }
    T Max() {
        if(currentsize==0)
         //throw OutOfBounds();
    return heap[1].right;
    }
    IntervalHeap<T>& Insert(const T& x);
    IntervalHeap<T>& DeleteMin(T& x);
    IntervalHeap<T>& DeleteMax(T& x);

    private:
    int currentsize;//number of elemnts in heap
    int Maxsize;//max elements permited
    TwoElement<T>*heap;//element  array
    };
template<class T>
IntervalHeap<T>::IntervalHeap(int currentsize)
{
    Maxsize=heapsize;
    //determine  number of array positions needed
    //array will be heap[0:n-1];
    int n=Maxsize/2+Maxsize%2+1;
    heap=new TwoElement<T>[n];
    currentsize=0;
    }
template<class T>
IntervalHeap<T>& IntervalHeap<T>::Insert(const T& x)
{
    if (currentsize==Maxsize)
        exit(1);
    if (currentsize<2)
    {
        if(x<heap[1].left)
            heap[1].left=x;
        else heap[1].right=x;
    else
    {
        heap[1].left=x;
        heap[1].right=x;
    }
    curentsize++;
    return *this;


    }
    int lastnode=currentsize/2+currentsize%2;
    bool minHeap;
    if (currentsize%2)
         if (x<heap[lastnode].left)
             minHeap=true;
         else
         {

             lastnode++;
             if (x<=heap[lastnode/2].left)
                 minheap=true;
             else
                 minheap=false;

         }
         if (minHeap) //fix min heap interval heap
         {
             int i=lastnode;
             while (i!=1 && x<heap[i/2].left){
                 heap[i].left=heap[i/2].left;
                 i/=2;



             }
             heap[i].left=x;
             currentsize++;
             if (currentsize%2)
                 heap[lastnode].right=heap[lastnode].left;


         }
         else
         {

             int i=lastnode;
             while(i!=1 &&  x>heap[i/2].right){
                  heap[i].right=heap[i/2].right;
                  i/=2;



             }

             heap[i].right=x;
             currentsize++;
             if (currentsize%2)
                 heap[lastnode].left=heap[lastnode].right;


         }
          return *this;


}
template<class T>
IntervalHeap<T>& IntervalHeap<T>::DeleteMax(T &x)
{
    if (currentsize==0)
        exit(1);
    x=heap[1].right;
    int lastnode=currentsize/2+currentsize%2;
    T y;
    if (currentsize %2)
    {
        y=heap[lastnode].left;
        lastnode--;
    }
    else{

        y=heap[lastnode].right;
        heap[lastnode].right=heap[lastnode].left;


    }
    currentsize--;
    int i=1,ci=2;
    while(ci<lastnode){

        if (ci<lastnode && heap[ci].right<heap[ci+1]) ci++;
         if (y>=heap[ci].right) break;
         //can't put y in  heap[i]
         heap[i].right=heap[ci].right;
         if (y<heap[ci].left)

             ::swap(y,heap[ci].left);
         i=ci;
         ci*=2;
    }

    heap[i].right=y;
    return *this;



}
template<class T>
IntervalHeap<T>& IntervalHeap<T>::DeleteMin(T &x)
{
     if (currentsize==0)
         exit(1);
     x=heap[1].left;
     int lastnode=currentsize/2+currentsize%2;
     T y;
     if (currentsize%2)
     {
         y=heap[lastnode].left;
         lastnode--;
     }
     else
     {
         y=heap[lastnode].right;
         heap[lastnode].right=heap[lastnode].left;

     }

     currentsize--;
     int i=1;
     int ci=2;
     while(ci<=lastnode) //find place for y
     {


          if (ci<lastnode && heap[ci].left>heap[ci+1].left) ci++;
          if (y<=heap[ci].left) break;
          heap[i].left=heap[ci].left;
          if (y>heap[ci].right)
              ::swap(y,heap[ci].right);
          i=ci;
          ci*=2;

     }
     if (i==lastnode && currentsize%2)
         heap[lastnode].left=heap[lastnode].right;
     else 
         heap[i].left=y;

     return *this

}


int main(){


    return 0;
}
#包括
#包括
使用名称空间std;
模板类间隔堆;
模板
二类元素
{
朋友级间隔;
公众:
我没有离开,
正确的;
};
模板
类间隔堆
{
公众:
间隔堆(int-heapsize=10);
~IntervalHeap(){delete[]heap;}
int size()常量{return currentsize;}
T Min()
{
如果(currentsize==0)
//抛出边界();
返回堆[1]。左;
}
T Max(){
如果(currentsize==0)
//抛出边界();
返回堆[1]。对;
}
间隔堆和插入(常数T和x);
间隔堆和删除最小值(T&x);
IntervalHeap和DeleteMax(T&x);
私人:
int currentsize;//堆中的元素数
int Maxsize;//允许的最大元素数
TwoElement*堆;//元素数组
};
模板
IntervalHeap::IntervalHeap(int currentsize)
{
Maxsize=heapsize;
//确定所需的阵列位置数
//数组将是堆[0:n-1];
int n=Maxsize/2+Maxsize%2+1;
heap=新的两个元素[n];
currentsize=0;
}
模板
间隔堆和间隔堆::插入(常量T&x)
{
如果(currentsize==Maxsize)
出口(1);

如果(currentsize我怀疑intellisense不适用于您的类,因为它是模板化的。它是哪个版本的visual studio?intellisense可能会失败,原因有很多,它是否实际完成了对代码的索引/编译,以及您的代码是否实际编译?

我以前也遇到过与vs2010相同的问题,因此我认为您可能只是在VisualStudio中,对IDE C++的限制有二级智能感知支持。