1841. 津津的书架

POCARI

multiset解决问题

include

using namespace std;
int main()
{
multiset st;
int num,mid;
cin>>num;
for(int i=0; i>mid;
st.insert(mid);
}
for(int m:st)
cout<<m<<endl;
return 0;
}

请PSG.LGD挑选冠军

把简单问题复杂化

include

include

typedef struct binaryTree
{
int elem;
struct binaryTree lchild, rchild, *parent;
} btr;

void insertNode(int num, btr root)
{
btr
temp = root;
while (temp != NULL)
{
if (num > temp->elem)
{
if (temp->lchild == NULL)
{
temp->lchild = (btr )malloc(sizeof(btr));
temp->lchild->elem = num;
temp->lchild->lchild = NULL;
temp->lchild->rchild = NULL;
temp->lchild->parent = NULL;
break;
}
else
{
temp = temp->lchild;
}
}
else
{
if (num <= temp->elem)
{
if (temp->rchild == NULL)
{
temp->rchild = (btr
)malloc(sizeof(btr));
temp->rchild->elem = num;
temp->rchild->lchild = NULL;
temp->rchild->rchild = NULL;
temp->rchild->parent = NULL;
break;
}
else
{
{
temp = temp->rchild;
}
}
}
}
}
}

btr createBsearchTr(int ArrList[], int length)
{
btr
root = (btr *)malloc(sizeof(btr));
root->elem = ArrList[0];
root->lchild = NULL;
root->rchild = NULL;
root->parent = NULL;
for (int i = 1; i < length; i++)
{
insertNode(ArrList[i], root);
}
return root;
}

void middleorder(btr *p)
{
if (p)
{
middleorder(p->rchild);
if (p->elem)
{
printf(“%d\n”, p->elem);
}
middleorder(p->lchild);
}
}

void BtrSort(int a[], int length)
{
btr *root = createBsearchTr(a, length);
middleorder(root);
}

void sort(int a[], int length)
{
BtrSort(a, length);
printf(“\n\n”);
}

int main()
{
int length;
scanf(“%d”, &length);
int a[length]={0};
for(int i =0; i<length; i++)
scanf(“%d”, &a[i]);
sort(a, length);
return 0;
}

你当前正在回复 博客/题目
存在问题!