编写一个能向表尾插入结点,并输出链表中所有数据元素的小程序
#ifndef _LINKLIST #define _LINKLIST
#include int data ; struct node *next ; }; typedef struct node *PLIST; typedef struct node NODE; /*创建链表,并初始化链表元素*/ PLIST createList_link() { PLIST head ,tail ,temp; int elem = -1; head = new NODE; //初始化头结点 if( head == NULL) { cout<<\"分配空间失败,链表创建失败\"< cin >> elem ; if(elem == 0 ) break ; temp = new NODE ; if(temp == NULL) { cout<<\"分配空间失败,链表创建失败\"< return head ; } void printList_link(PLIST head ) { /*在此处完成任务,输出head为表头的单链表数据元素*/ //begin PLIST p =new NODE; p=head->next; while(p){ printf(\"%d \ p=p->next; } //end } void insertDataTail(PLIST head , int insData ) { /*在此处完成任务,在head为表头的单链表表尾插入数据元素insData*/ //begin PLIST p; p=head->next; while(p->next!=NULL){ p=p->next; } PLIST q = new NODE; //初始化结点 p->next=q; q->data=insData; q->next=NULL; //end } #endif 因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- dcrkj.com 版权所有 赣ICP备2024042791号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务