c语言线性表的逆转,数据结构(C语言)设有一个线性表E,将线性表逆置,要求逆线性表占? 爱问知识人...
輸入數(shù)據(jù),輸出數(shù)據(jù),及線(xiàn)性表的長(zhǎng)度,
詢(xún)問(wèn)是否查找數(shù)據(jù),若查找則由用戶(hù)輸入需查找的數(shù)據(jù),顯示此數(shù)據(jù)在線(xiàn)性表中的位置(第幾個(gè))
*/
#include
#include
#define NULL 0
#define LEN sizeof(struct Node)
struct Node
{
int num;
struct Node* next;
};
struct Node *createline();
void showline(struct Node *head);
int getlen(struct Node *head);
int selectline(struct Node *head,int data);
int main()
{
struct Node *head;
int selflag;
int len = 0;
head = createline();
if(head == NULL)
{
printf("create error
");
return 1;
}
showline(head);
printf("line's len is %d
",getlen(head));
printf("0 select,other not select
");
scanf("%d",&selflag);
if(selflag == 0)
{
printf("請(qǐng)輸入要查找的數(shù)字:");
scanf("%d",&selflag);
len = selectline(head,selflag);
if(len num);
p1->next = NULL;
if(i == 0)
{
head = p1;
}
else
{
p2->next = p1;
}
p2 = p1;
}
return head;
}
void showline(struct Node *head)
{
struct Node *p1;
p1 = head;
while(p1)
{
printf("%d ",p1->num);
p1 = p1->next;
}
printf("
");
return ;
}
int getlen(struct Node *head)
{
int len = 0;
struct Node *p1;
p1 = head;
while(p1)
{
len = 1;
p1 = p1->next;
}
return len;
}
int selectline(struct Node *head,int data)
{
int len = 1;
int flag = 0;
struct Node *p1;
p1 = head;
while(p1)
{
if(p1->num == data)
{
flag = 1;
break;
}
len = 1;
p1=p1->next;
}
if(flag == 0)
{
len = -1;
}
return len;
}
另外,站長(zhǎng)團(tuán)上有產(chǎn)品團(tuán)購(gòu),便宜有保證。
全部
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專(zhuān)家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的c语言线性表的逆转,数据结构(C语言)设有一个线性表E,将线性表逆置,要求逆线性表占? 爱问知识人...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: c语言函数打印零星,C语言零星笔记--(
- 下一篇: c语言 五子棋 悔棋代码,跪求C语言五子