c++ - 使用 vector 对元音和辅音排序链接列表

标签 c++ linked-list

我试图通过使用2个 vector 在堆栈中存储和更新指针,在链接列表中排列元音和辅音。
但是,下面的代码片段都没有工作,我在哪里出错?
甚至main中的cout都在安排函数调用之前,并且也没有显示。

using namespace std;
bool r(char a,char b)
{
    return a>b;
}

struct node{
    char a;
    struct node* next;
};
struct node* head;
void push(char data)
{
    node* temp=new node;
    temp->a=data;

    if(head==NULL)
    {
        head=temp;
        temp->next=NULL;
    }
    else
    {
        temp->next=head;
        head=temp;
    }

}

void arrange()
{
    vector<node*> q1;
    vector<node*> q2;
    node* temp=head;

    while(temp!=NULL)
    {
        if(temp->a=='a'||temp->a=='e')
            q1.push_back(temp);
        else
            q2.push_back(temp);

        temp=temp->next;
    }
    
    head=q1[0];

    cout<<head->next->a<<q1.size();

    for(int i=0;i<=q1.size();i++)
    {
        if(i==q1.size())
            q1[i]->next=q2[0];
        else
            q1[i]->next=q1[i+1];
    }
    for(int i=0;i<=q2.size();i++)
    {
        if(i==q2.size())
            q2[i]->next=NULL;
        else
            q2[i]->next=q2[i+1];
    }

    node* t=head;

    while(t!=NULL)
    {
        cout<<t->a;
        t=t->next;
    }

}

int main() 
{ 
    
    head=NULL;
    push('a');
    push('b');
    push('c');
    push('d');
    push('e');
    push('f');

    node* temp=head;

    while(temp!=NULL)
    {
        cout<<temp->a;
        temp=temp->next;
    }
    
    arrange();

    return 0; 
} 
只有当我在安排功能中删除for循环时,cout才能正常工作

最佳答案

请测试if (cout)以查看cout是否存在问题。如果有问题,请报告给cerr

关于c++ - 使用 vector 对元音和辅音排序链接列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63868436/

相关文章:

c++ - 在 g++ 4.8.1 中使用枚举启用_if

c++ - 字符串作为 C++ 中宏的参数

c++ - 内存映射文件是否为大缓冲区提供了优势?

c - C 中细粒度的线程安全链表

java - 我的反转链表的代码有什么问题?

c - 如何删除链表中的头节点? C

c++ - C++ 中 numeric_limits<streamsize>::max() 的值

c++ - 给定一个随机数列表 [0, 1] : can I use the standard library to convert to a specific distribution?

c - 链接列表无法正常工作

python - 如何在python中将链表列表中的链表节点放置到堆上