有一个长度为n以顺序结构存储的线性表,结点值均为正整数,编写一个算法,把该线性表分解为两个线性表,其中一个线性表的结点值均为奇数,另一个线性表的结点值均为偶数.

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 10:42:08
有一个长度为n以顺序结构存储的线性表,结点值均为正整数,编写一个算法,把该线性表分解为两个线性表,其中一个线性表的结点值均为奇数,另一个线性表的结点值均为偶数.

有一个长度为n以顺序结构存储的线性表,结点值均为正整数,编写一个算法,把该线性表分解为两个线性表,其中一个线性表的结点值均为奇数,另一个线性表的结点值均为偶数.
有一个长度为n以顺序结构存储的线性表,结点值均为正整数,编写一个算法,把该线性表分解为两个线性表,其
中一个线性表的结点值均为奇数,另一个线性表的结点值均为偶数.

有一个长度为n以顺序结构存储的线性表,结点值均为正整数,编写一个算法,把该线性表分解为两个线性表,其中一个线性表的结点值均为奇数,另一个线性表的结点值均为偶数.
//不知道可不可以,你试下
#include
#include
#include
struct node
{
int date;//数据域
struct node *pn;//指针域
};

struct node* init(int x);
void insert(struct node *phead,int pos,int *pval);
bool isempty(struct node *phead);
bool isfull(struct node *phead);
void show(struct node *phead);
int lenth(struct node *phead);

struct node* init(int x)//初始化链表,给链表赋值
{

int val;
struct node *phead=(struct node*)malloc(sizeof(struct node));
if(NULL==phead)
{
printf("内存分配失败!\n");
exit(-1);
}
struct node *ptail;
ptail=phead;
ptail->pn=NULL;
if(x==0)
{
return phead;

}
printf("输入%d个数\n",x);
for(int a=0;adate=val;
ptail->pn=p;
p->pn=NULL;
ptail=p;
}
return phead;
}
void show(struct node *phead)
{
if(phead->pn==NULL)
{
printf("链表为空!\n");
//exit(-1);
}
struct node *p=phead->pn;
while(p!=NULL)
{
printf(" %d ",p->date);
p=p->pn;
}
printf("\n");
}
int lenth(struct node *phead)
{
int len=0;
struct node *p=phead->pn;

while(p!=NULL)
{
len=len+1;
p=p->pn;
}
return len;
}
bool isempty(struct node *phead)
{
if(phead->pn==NULL)
{
return true;
}
else
{
return false;
}
}
bool isfull(struct node *phead)
{
if(phead->pn!=NULL)
{
return true;
}
else
{
return false;
}
}
bool insert(struct node *phead,int pos,int pval)
{
int i=0;
struct node *p=phead;
while(NULL!=p&&ipn;
++i;
}
if(i>pos-1||NULL==p)
{
return false;
}
struct node * pnew=(struct node *)malloc(sizeof(struct node ));
if(NULL==pnew)
{
printf("动态内存分配失败!");
exit(-1);
}
pnew->date=pval;
struct node * q=p->pn;
p->pn=pnew;
pnew->pn=q;
return true;

}
int main()
{
struct node *phead1;//头指针
struct node *phead2;
struct node *phead3;
int pval;
int a=1,b=1;
phead1=init(10);
phead2=init(0);
phead3=init(0);
printf("线性表1中的元素是:\n");
show(phead1);
struct node *p=phead1->pn;
while(p!=NULL)
{
if((p->date)%2==1)
{
insert(phead3,a,p->date);
a++;
}
if((p->date)%2==0)
{
insert(phead2,b,p->date);
b++;
}
p=p->pn;

}
printf("线性表2中的元素(偶数):\n");
show(phead2);
printf("线性表3中的元素(奇数):\n");
show(phead3);
return 0;
}

有一个长度为n以顺序结构存储的线性表,结点值均为正整数,编写一个算法,把该线性表分解为两个线性表,其中一个线性表的结点值均为奇数,另一个线性表的结点值均为偶数. 为什么若长度为n的线性表采用顺序存储结构在其第i个位置插入一个新元素的时间复杂O(n)(1 已知长度为n的线性表A采用顺序存储结构,请写出一个时间复杂度为O(n)、空间复杂度为O(1)的算法,该算法可删除线性表中所有值为item的数据元素. 对于长度为n的顺序存储的线性表,当随机插入和删除一个元素时,需平均移动元素的个数为 已知长度为n的线性表A采用顺序存储结构,请写一算法,找出该线性表中值最小的数据元素.需要完整能运行的,C C++都可以 线性表的顺序存储结构和线性表的链式存储结构分别是A) 顺序存取的存储结构、顺序存取的存储结构B) 随机存取的存储结构、顺序存取的存储结构C) 随机存取的存储结构、随机存取的存储结 试分析在顺序存储结构的线性表中插入一个元素的时间复杂度? 若长度为n的线性表采用顺序存储结构,在第i个位置插入一个元素,需要它依次向后移动______数据元素.A.n-iB.n-i+1C.n-i-1D.i- - 给我个解题思路吧..别只有ABCD的答案.. 2.在长度为n的顺序存储的线性表中删除第i个元素(1≤i≤n)需向前移动_____个元素.1.在长度为n的顺序存储的线性表中删除第i个元素(1≤i≤n)需向前移动____个元素.2.在长度为n的顺序存储的线性 在顺序存储结构的线性表中插入一个元素,平均需要移动( )个元素我算出来是 (n+1)/2可是答案是 n/2为什么是n/2 九、 线性表的链式存储结构与顺序存储结构比较有何特点?这两种结构分别适合在什么情况下使用? //已知长度为n的线性表A采用顺序存储结构,请写一段时间复杂度为O(n)的算法,该算法删除线性表中原来序号为奇数的那些数据元素.怎么用C语言编写整个程序,包括主函数,在C语言可以运行得的, 一直长度为n的线性表A中的元素是整数,写算法删除线性表中所有值为item的数据元素.分两种情况编写函数:(1)线性表采用顺序存储;(2)线性表采用单链接表存储还有一道是求线性表中值大于item 急……写出线性表顺序存储结构的描述1 写出线性表顺序存储结构的描述;2 采用顺序存储结构存储一个线性表,并在该表的第2个位置上插入一个元素(元素的取值自已给定),用C语言实现这 设有一个线性表采用顺序存储结构,表中的数据元素值为正整数(n个).设在O(n) 时间内,将线性表分成两为两部分,其中左半部分每个元素都小于原表的第一个元素,而右半部分则相反. 在一个长度为n顺序线性表中顺序查找值为x的元素时,查找的平均长度为 4. 在一个长度为n的顺序存储的线性表中,向第i个元素(1≤i≤n+1)位置之前插入一个新元素时,需要移动________个元素.A. n-i B. n-i+1 C. n-i-1 D. i 数据结构假设分别以两个元素的值递增有序线性表a,b表示两个集合,现在要构成一个新的线性表c,c表示a b的交,且c中的元素也递增有序.分别以顺序表和单链式表为存储结构,编写程序