我正在做树。它没有显示。
我有一个长度为 4 的字符串,说 SHAM 现在每个字符 SHAM 都有四个指针并在其中放入 NULL。但是当我编译并运行 display() 函数时不起作用。
struct node
{
string info;
struct node **next;
} *front, *rear;
void enqueue(string s)
{
node *p, *temp;
p=new node[sizeof(node)];
stuff goes here...
}
}
void display()
{
int k = 0;
node *t, *temp;
t = front;
if(front == NULL || rear == NULL)
{
cout<<"\nQueue Empty!!!";
}
else
{
temp=t;
while(t!= NULL)
{
if(t->next[k] != NULL)
{
temp=t->next[k];
cout<<temp->info<<" ";
}
k++;
if(k==n.length())
{
k = 0;
t = t->next[k];
temp = t;
}
}
}
}
int main(int argc, char** argv)
{
int ch, len, x;
string string1;
rear = NULL;
front = NULL;
cout << "\n1. Insert\n2. Exit\n";
cout << "\nEnter Your Choice: ";
cin >> ch;
switch(ch)
{
case 1:
cout << "\nEnter The String: ";
cin >> n;
len = n.length();
enqueue(n);
cout << " len " << len;
for(int p=1;p<=len;p++)
bnod+=pow(len,p);
cl = 0;
for (x = 0; x < len; x++)
{
string1=n.at(x);
enqueue(string1);
cl++;
}
display();
cout << "\n########################\n";
break;
case 2:
exit(0);
break;
default:
cout << "\nWrong Choice!!! Try Again.";
}
return 0;
}