#include <iostream>
using namespace std; typedef struct Node
{
Node *next;
int data;
}Node, *List; typedef struct DNode
{
DNode *prior;
DNode *next;
int data;
}DNode, *DList; void creatList(List &l)
{
l = new Node;
Node *p = l;
int data;
while ((cin>>data) && data != -)
{
Node *q= new Node;
q ->data = data;
p ->next = q;
p = p->next;
}
p ->next = nullptr;
} void printList(List &l)
{
Node *p = l->next;
while (p)
{
cout<<p->data<<" ";
p = p->next;
}
cout<<endl;
} void reversePrint(List &l)
{
Node *p =l;
if (p->next != nullptr)
reversePrint(p->next);
cout<<p->data<<" ";
} void removeMin(List &l)
{
Node *p = l->next;
int min = p->data;
Node *flag = nullptr;
while (p)
{
if (p->next ==nullptr) break ;
if (p->next->data < min)
{
min = p->next->data;
flag = p;
}
p = p->next;
} Node *q = flag ->next;
flag ->next = q->next;
free(q);
} void reverseList (List &l)
{
Node *p = l->next;
l->next = nullptr;
Node *q;
while (p)
{
q = p->next;
p->next = l->next;
l->next = p;
p = q;
}
} void selectSort(List &l)
{
Node * p = l->next;
while (p)
{
Node *q = p->next;
Node *flag = p;
while (q)
{
if (q->data < flag->data)
flag = q;
q = q->next;
}
swap (p->data,flag->data);
p = p->next;
}
} void removeMM(List &l)
{
Node* p = l->next;
Node* min = p;
Node* max = p;
while (p)
{
if (p->data > max->data)
max = p;
if (p->data < min->data)
min = p;
p = p->next;
} Node* q = l; while (q)
{
Node * s = q->next;
if ((s->data>min->data) && (s->data<max->data ))
{
q ->next = s->next;
free(s);
}
q = q->next;
}
} int length(List &l)
{
int i = ;
if (!l || !l->next)
return ;
Node *p = l->next;
while (p)
{
i++;
p = p->next;
}
return i;
} Node* Search_1st_common(List &l1,List &l2)
{
int len1 = length(l1);
int len2 = length(l2); List longList = (len1>len2)?l1:l2;
List shortList = (len1<len2)?l1:l2;
int dist = (len1>len2)?(len1-len2):(len2-len1); while (dist--) longList = longList->next; while (longList)
{
if (longList->data == shortList->data)
return longList;
else
{
longList = longList->next;
shortList = shortList->next;
}
}
return nullptr;
} void freeALL(List &l)
{
while (l->next)
{
Node* pre = l;
Node*p = pre->next; while (p->next)
{
if (p->next->data<pre->next->data)
pre = p;
p = p->next;
}
printf("%d ",pre->next->data);
Node *u = pre->next;
pre->next =u->next;
free (u);
}
free(l);
} void divideList(List &l,List &r1)
{
Node *p = l->next;
r1 = new Node;
Node *r = r1;
while (p->next)
{
Node* s = new Node;
s->data = p->next->data;
Node* t = p->next;
p ->next = t->next;
r->next = s;
r = r-> next;
free(t);
p = p->next;
}
r->next = nullptr;
} void removeCF(List &l)
{
Node *p = l->next;
while (p->next)
{
Node *q = p->next;
if (q->data == p->data)
{
p->next = q->next;
free(q);
}
else
p = p->next;
}
} void MergeList(List &l1,List &l2)
{
Node *p = l1->next;
Node *q = l2->next;
l1->next = nullptr;
Node *s;
while (p && q)
{
if (p->data<q->data)
{
s = p->next;
p->next = l1->next;
l1->next = p;
p = s;
}
else {
s = q->next;
q->next = l1->next;
l1->next = q;
q = s;
}
} if (p) q = p; while (q)
{
s = q->next;
q->next = l1->next;
l1->next = q;
q = s;
}
} void inserthead(List &l)
{
l = new Node;
l ->next =nullptr; Node *s;
int data;
while (cin>>data && data != -)
{
s = new Node;
s ->data = data;
s ->next = l->next;
l ->next = s;
}
} List getCommon(List &l1,List &l2)
{
List l3 = new Node;
Node *p = l1->next;
Node *q = l2->next;
Node *t = l3;
while (p && q)
{
if (p->data == q->data)
{
Node* s = new Node;
s->data = p->data;
t ->next = s;
t = t->next;
p = p->next;
q = q->next;
}
else if (p->data > q->data)
q = q->next;
else p = p->next;
}
t->next = nullptr;
return l3;
} void UnionList(List &l1,List &l2)
{
Node *p = l1->next;
Node *q = l2->next;
Node *s = l1, *u; while (p && q)
{
if (p->data == q->data)
{
s->next = p;
s = p;
u = q;
q = q->next;
p = p->next;
free (u);
}
else if (p->data > q->data)
{
u = q;
q = q->next;
free (u);
}
else { u = p ; p = p->next ; free (u);}
}
while (p) { u = p; p = p->next; free (u);}
while (q) { u = q; q = q->next; free (u);}
s ->next = nullptr;
free (l2);
} bool isSubseq(List &l1,List &l2)
{
Node *p = l1->next;
Node *q = l2->next; Node *s = p;
while (p && q)
{
if (p->data == q->data)
{
p = p->next;
q = q->next;
}
else
{
s = s->next;
p = s;
q = l2->next;
}
}
if (!q) return true;
else return false;
} void crtDbCirList(DList &l)
{
l = new DNode;
DNode*p = l; int data;
while (cin>>data && data != -)
{
DNode* q = new DNode;
q ->data = data;
p ->next = q;
q ->prior = p;
p = p->next;
}
p ->next = l->next;
l ->next ->prior = p;
} bool isSymmetry(DList &dl)
{
DNode *p = dl->next;
DNode *q = dl->next->prior; while ( p != q && (p->next != q->prior))
{
//printf ("fuck");
if (p->data == q->data)
{
p = p->next;
q = q->prior;
}
else return false;
} return true;
} int main()
{
/*List s;
List s2;
creatList(s);
creatList(s2);
*/
//printList(s);
//printList(s2);
//reversePrint(s);
//removeMin(s);
//reverseList(s);
//selectSort(s);
//printList(s);
//cout<<length(s)<<endl<<length(s2)<<endl;
//cout<<Search_1st_common(s, s2)->data<<endl; /*List s2;
divideList(s, s2);
printList(s);
printList(s2);
*/ //removeCF(s);
//MergeList(s,s2);
//List s3 = getCommon(s, s2);
//printList(s3); //UnionList(s, s2);
//printList(s);
//cout<<isSubseq(s, s2)<<endl; DList dl;
crtDbCirList(dl);
DNode *q = dl->next;
DNode *f = dl->next->prior; cout<<q->data<<" "<<f->prior->data<<endl; if (isSymmetry(dl)) cout<<"success"<<endl;
else cout<<"fail"<<endl; return ;
}

Exercise DS的更多相关文章

  1. MIT 6.828 JOS学习笔记5. Exercise 1.3

    Lab 1 Exercise 3 设置一个断点在地址0x7c00处,这是boot sector被加载的位置.然后让程序继续运行直到这个断点.跟踪/boot/boot.S文件的每一条指令,同时使用boo ...

  2. MIT 6.828 JOS学习笔记3. Exercise 1.2

    这篇博文是对Lab 1中的Exercise 2的解答~ Lab 1 Exercise 2: 使用GDB的'si'命令,去追踪ROM BIOS几条指令,并且试图去猜测,它是在做什么.但是不需要把每个细节 ...

  3. 《MIT 6.828 Lab 1 Exercise 7》实验报告

    本实验链接:mit 6.828 lab1 Exercise 7. 题目 Exercise 7. Use QEMU and GDB to trace into the JOS kernel and st ...

  4. 《MIT 6.828 Lab 1 Exercise 3》实验报告

    本实验的网站链接:mit 6.828 lab1 Exercise 3. 题目 Exercise 3. Take a look at the lab tools guide, especially th ...

  5. symmetry methods for differential equations,exercise 1.4

    tex文档: \documentclass[a4paper, 12pt]{article} % Font size (can be 10pt, 11pt or 12pt) and paper size ...

  6. 创建Azure DS 虚拟机并附加SSD硬盘

    $subscriptionName = "Windows Azure Enterprise Trial" #订阅名称 $location = "China East&qu ...

  7. MIT 6.828 JOS学习笔记12 Exercise 1.9

    Lab 1中Exercise 9的解答报告 Exercise 1.9: 判断一下操作系统内核是从哪条指令开始初始化它的堆栈空间的,以及这个堆栈坐落在内存的哪个地方?内核是如何给它的堆栈保留一块内存空间 ...

  8. MIT 6.828 JOS学习笔记13 Exercise 1.10

    Lab 1 Exercise 10 为了能够更好的了解在x86上的C程序调用过程的细节,我们首先找到在obj/kern/kern.asm中test_backtrace子程序的地址, 设置断点,并且探讨 ...

  9. MIT 6.828 JOS学习笔记11 Exercise 1.8

    Exercise 1.8       我们丢弃了一小部分代码---即当我们在printf中指定输出"%o"格式的字符串,即八进制格式的代码.尝试去完成这部分程序. 解答: 在这个练 ...

随机推荐

  1. Yii框架zii.widgets.grid自定义按钮,ajax触发事件并提示

    相关类手册: http://www.yiichina.com/api/CButtonColumn   buttons 属性 public array $buttons; the configurati ...

  2. IOS开发之内存管理--dealloc该写些什么

    在非ARC开发环境中,dealloc是类释放前,清理内存的最后机会.到底那些变量和属性该释放呢,一些特殊的类(nstimer,observer)该怎么释放.需要注意的是不释放会引起内存泄露,过度释放也 ...

  3. 动态生成修改aspx文件

    using System.IO; using System.Text;/// <summary>/// SCPage 的摘要说明 修改 aspx 和aspx.cs文件/// </su ...

  4. angular2自学笔记---官网项目(一)

    1.单向数据绑定的'插值表达式' angular中最典型的数据显示方式:把HTML模板(template)的控件绑定到angular组件的属性(component相当于一个构造函数,下面例子中的这个构 ...

  5. Java 抽象类与接口总结

    一.为什么要使用抽象类?有什么好处? 抽象类是通用接口.不同的子类可以用不同的方法表示此接口.通用接口建立起一种基本形式,以此表示所有子类的共同部分. 必须覆写父类abstract抽象的方法  含有抽 ...

  6. mybatis update语句参数正常, 数据没有更新

    昨天做的一个功能, 更新每天支付宝账号的所有订单收益 ,有一个update 语句:

  7. chrome下老是弹出网页显示 true

    事实上这个问题是chrome下安装了一些插件的原因,一般来说是安装迅雷插件会出现这个问题,删除迅雷插件就好了.

  8. console.debug()浏览器控制台打印输出 仅仅在支持console的浏览器下打印

    console.debug()浏览器控制台打印输出 仅仅在支持console的浏览器下打印 var util = {}; /** * 工具类 */ util = new function() { /* ...

  9. ubuntu权限管理常用命令 分类: linux ubuntu 学习笔记 2015-07-05 14:15 77人阅读 评论(0) 收藏

    1.chmod 第一种方式 chomd [{ugoa}{+-=}{rwx}] [文件或者目录] u 代表该文件所属用户 g 代表该文件所属用户组 o 代表访客 a 代表所有用户 +-=分别表示增加权限 ...

  10. Managing Group Policy with PowerShell

    Overview In this article, I’ll talk about your options when it comes to managing Group Policy using ...