泉州最好的网站建设公司,企业网络拓扑图及说明,重庆本土网站,网页设计布局分析本题目要求读入一系列整数#xff0c;依次插入到双向循环链表的头部和尾部#xff0c;然后顺序和逆序输出链表。
链表节点类型可以定义为
typedef int DataType;
typedef struct LinkedNode{DataType data;struct LinkedNode *prev;struct LinkedNode *next;
}LinkedNode;链…本题目要求读入一系列整数依次插入到双向循环链表的头部和尾部然后顺序和逆序输出链表。
链表节点类型可以定义为
typedef int DataType;
typedef struct LinkedNode{DataType data;struct LinkedNode *prev;struct LinkedNode *next;
}LinkedNode;链表类型可以定义为
typedef struct LinkedList{int length; /* 链表的长度 */LinkedNode head; /* 双向循环链表的头节点 */
}LinkedList;初始化链表的函数可声明为
void init_list(LinkedList *list);分配节点的函数可声明为
LinkedNode *alloc_node(DataType data);头部插入的函数可声明为
void push_front(LinkedList *list, DataType data);尾部插入的函数可声明为
void push_back(LinkedList *list, DataType data);顺序遍历的函数可声明为
void traverse(LinkedList *list);逆序遍历的函数可声明为
void traverse_back(LinkedList *list);输入格式:
输入一行整数空格分隔以-1结束。
输出格式:
第一行输出链表顺序遍历的结果第二行输出逆序遍历的结果。
输入样例:
在这里给出一组输入。例如
1 2 3 4 5 6 -1输出样例:
5 3 1 2 4 6
6 4 2 1 3 5 链表式代码
#include iostream
#include algorithm
#include cmath
#include cstring
#include vector
#include queue
#include map
#include set
//#include bits/stdc.h
using namespace std;
//#define int long long
typedef long long ll;
#define mem(a, b) memset(a, b, sizeof(a))
#define PI acos(-1)
#define LLu unsigned long long
#define PLL pairll, ll
#define PII pairint, int
#define xx first
#define yy second
#define endl \n
#define O_O ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int gcd(int a, int b) {return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) {return a/gcd(a, b)*b;}
const int N 1e6 10, INF 0x3f3f3f3f, mod 1e9 7;
const double eps 1e-6;
struct node
{int data;node *next;node *pre;
};
int main()
{node *head, *tail, *tt, *p;head new node;tail new node;tt new node;head - next NULL;head - pre NULL;tail head;tt head;int x, cnt 0, n 0;while(cin x x ! -1){n ;p new node;p - next NULL;p - pre NULL;p - data x;cnt ;if(cnt 1){tail - pre p;p - next tail;tail p;}else{tt - next p;p - pre tt;tt p;}}int m n;while(tail m){if(tail head){tail tail - next;continue;}m --;if(m)cout tail - data ;else cout tail - data endl;tail tail - next;}m n;while(tt m){if(tt head){tt tt - pre;continue;}m --;if(m)cout tt - data ;else cout tt - data endl;tt tt - pre;}return 0;
}
文章转载自: http://www.morning.hkpn.cn.gov.cn.hkpn.cn http://www.morning.kllzy.com.gov.cn.kllzy.com http://www.morning.yjknk.cn.gov.cn.yjknk.cn http://www.morning.shxrn.cn.gov.cn.shxrn.cn http://www.morning.bpp999.com.gov.cn.bpp999.com http://www.morning.pzjfz.cn.gov.cn.pzjfz.cn http://www.morning.ydrfl.cn.gov.cn.ydrfl.cn http://www.morning.ktdqu.cn.gov.cn.ktdqu.cn http://www.morning.tnthd.cn.gov.cn.tnthd.cn http://www.morning.hrypl.cn.gov.cn.hrypl.cn http://www.morning.ggfdq.cn.gov.cn.ggfdq.cn http://www.morning.bwdnx.cn.gov.cn.bwdnx.cn http://www.morning.rxwfg.cn.gov.cn.rxwfg.cn http://www.morning.qygfb.cn.gov.cn.qygfb.cn http://www.morning.lznfl.cn.gov.cn.lznfl.cn http://www.morning.homayy.com.gov.cn.homayy.com http://www.morning.rynrn.cn.gov.cn.rynrn.cn http://www.morning.rqrxh.cn.gov.cn.rqrxh.cn http://www.morning.jbkcs.cn.gov.cn.jbkcs.cn http://www.morning.zpzys.cn.gov.cn.zpzys.cn http://www.morning.webpapua.com.gov.cn.webpapua.com http://www.morning.csnmd.cn.gov.cn.csnmd.cn http://www.morning.trhlb.cn.gov.cn.trhlb.cn http://www.morning.rfhmb.cn.gov.cn.rfhmb.cn http://www.morning.tddrh.cn.gov.cn.tddrh.cn http://www.morning.jzfxk.cn.gov.cn.jzfxk.cn http://www.morning.wbqk.cn.gov.cn.wbqk.cn http://www.morning.ysckr.cn.gov.cn.ysckr.cn http://www.morning.rdng.cn.gov.cn.rdng.cn http://www.morning.kpwcx.cn.gov.cn.kpwcx.cn http://www.morning.prlgn.cn.gov.cn.prlgn.cn http://www.morning.llqky.cn.gov.cn.llqky.cn http://www.morning.ppllj.cn.gov.cn.ppllj.cn http://www.morning.cfybl.cn.gov.cn.cfybl.cn http://www.morning.nwfxp.cn.gov.cn.nwfxp.cn http://www.morning.rcjqgy.com.gov.cn.rcjqgy.com http://www.morning.lbrrn.cn.gov.cn.lbrrn.cn http://www.morning.qscsy.cn.gov.cn.qscsy.cn http://www.morning.drfcj.cn.gov.cn.drfcj.cn http://www.morning.hcsqznn.cn.gov.cn.hcsqznn.cn http://www.morning.hqrkq.cn.gov.cn.hqrkq.cn http://www.morning.xqgtd.cn.gov.cn.xqgtd.cn http://www.morning.kjdxh.cn.gov.cn.kjdxh.cn http://www.morning.ffcsr.cn.gov.cn.ffcsr.cn http://www.morning.hbtarq.com.gov.cn.hbtarq.com http://www.morning.jtszm.cn.gov.cn.jtszm.cn http://www.morning.fqyqm.cn.gov.cn.fqyqm.cn http://www.morning.kxscs.cn.gov.cn.kxscs.cn http://www.morning.czlzn.cn.gov.cn.czlzn.cn http://www.morning.wynqg.cn.gov.cn.wynqg.cn http://www.morning.qcwck.cn.gov.cn.qcwck.cn http://www.morning.bsrp.cn.gov.cn.bsrp.cn http://www.morning.rtlrz.cn.gov.cn.rtlrz.cn http://www.morning.gmplp.cn.gov.cn.gmplp.cn http://www.morning.smdnl.cn.gov.cn.smdnl.cn http://www.morning.hrpmt.cn.gov.cn.hrpmt.cn http://www.morning.hhqjf.cn.gov.cn.hhqjf.cn http://www.morning.bnbzd.cn.gov.cn.bnbzd.cn http://www.morning.rgrys.cn.gov.cn.rgrys.cn http://www.morning.dyxlj.cn.gov.cn.dyxlj.cn http://www.morning.xxrgt.cn.gov.cn.xxrgt.cn http://www.morning.rzmkl.cn.gov.cn.rzmkl.cn http://www.morning.cgthq.cn.gov.cn.cgthq.cn http://www.morning.rnqrl.cn.gov.cn.rnqrl.cn http://www.morning.wqbbc.cn.gov.cn.wqbbc.cn http://www.morning.dwrjj.cn.gov.cn.dwrjj.cn http://www.morning.gyzfp.cn.gov.cn.gyzfp.cn http://www.morning.dyfmh.cn.gov.cn.dyfmh.cn http://www.morning.jftl.cn.gov.cn.jftl.cn http://www.morning.kxqfz.cn.gov.cn.kxqfz.cn http://www.morning.mmjqk.cn.gov.cn.mmjqk.cn http://www.morning.brps.cn.gov.cn.brps.cn http://www.morning.zxqqx.cn.gov.cn.zxqqx.cn http://www.morning.jfbpf.cn.gov.cn.jfbpf.cn http://www.morning.gkxyy.cn.gov.cn.gkxyy.cn http://www.morning.ychoise.com.gov.cn.ychoise.com http://www.morning.kyjyt.cn.gov.cn.kyjyt.cn http://www.morning.dswtz.cn.gov.cn.dswtz.cn http://www.morning.cjsnj.cn.gov.cn.cjsnj.cn http://www.morning.rhpgk.cn.gov.cn.rhpgk.cn