#include<stdio.h> #include <stdlib.h> typedef struct Lnode{ char data;/*資料域,保存節點的值,*/ struct Lnode*next;/*指標域*/ } LNode;/*節點的型別*/ LNode *CreateList_L(int n); void DispalyList(LNode*L); void main(){ int i; LNode *head; printf("請輸入單鏈表的長度:"); scanf("%d",&i); getchar(); head=CreateList_L(i); DispalyList(head); } LNode *CreateList_L(int n){ char ch; int i; LNode*head,*p ,*q; head=(LNode*)malloc(sizeof(LNode)); head->next=NULL; p=head; for(i=1;i<=n;i++){ printf("創建第%d個節點\n",i); scanf("%c",&ch); getchar(); q=(LNode*)malloc(sizeof(LNode)); q->data=https://www.cnblogs.com/LLiRo/p/ch; q->next=p->next;p->next=q;p=q; } return head; } void DispalyList(LNode*L){ LNode *p; p=L; p=p->next; printf("該單鏈表中的資料元素是:"); while(p!=NULL){ printf("%c ",p->data); p=p->next; } }
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/47138.html
標籤:C++
上一篇:2020年3月28日UCF Local Programming Contest 2016
下一篇:順序演算法
