数据结构作业 哪位大虾帮帮忙(月底要交)

2024-11-28 14:24:41
推荐回答(1个)
回答1:

第一题:
#include
#include

using namespace std;

struct celltype
{
int element;
celltype * next;
};
typedef celltype * LIST;
typedef celltype * position;

void Creat (LIST &L);
void Cout(LIST L);
void ChangTo(LIST &L);

int main()
{
LIST list;
Creat(list);
Cout(list);
ChangTo(list);
system("PAUSE");
cout<Cout(list);

cout<<"\n这是啥啊"<system("PAUSE");
return 0;
}

void Creat (LIST &L)
{
L = new celltype;
L->next = NULL;

int length = 0;
position q = L;
for(int i = 1;i <= 10;i ++)
{

LIST cel = new celltype;
q->next = cel;
cel->next = NULL;
q = q->next;
cout<<"请输入第 "<cin>>cel->element;
length ++;
}
} //初始化单链表

void Cout(LIST L)
{
position q;
q = L->next;
while(q)
{
cout<element<<" ";
q = q->next;
}

}//单链表输出

void ChangTo(LIST &L)
{

if(L == NULL)
return ;
else if(L->next == NULL)
return ;
else
{
position p,q,t;
p = L;
q = p->next;

while(q != NULL)
{
LIST temp = q->next;
q->next = p;
p = q;
q = temp;
}

L->next->next = NULL;
L->next = p;
return ;
}
}
===============================================================
第2题 插入排序
void Sort(int n,LIST A)
{
int i,j;
A[0].key = -1;
for(int i = 1;i <= n;i ++)
{
j = i;
while(A[j].key < A[j-1].key)
{
Swap(A[j],A[j-1]);
j = j - 1;
}
}
}
===========================================================
第五题 冒泡
int main()
{
int a[] ={50,31,122,77,27,38};
for(int i = 0;i < 6;i ++)
for(int j = 5; j >= i+1;j --)
{
if(a[j-1] {
int temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
}
}
for(int i = 0;i < 6;i ++)
cout<