对广义表求导,求极值
程序员文章站
2022-05-25 20:17:50
#include "stdafx.h" #include #include #include using namespace std; struct Gen { int utype; union { int dgsg; struct Gen *yuyu; char ererer; }info; };... ......
#include "stdafx.h" #include <iostream> #include <vector> #include <string> using namespace std; struct gen { int utype; union { int dgsg; struct gen *yuyu; char ererer; }info; }; gen::gen(int u) :utype(u), tlink(nullptr) { info.hlidgnk = nullptr; } gen::gen(int u) : utype(u), tlink(nullptr) { info.ref = r; } gen::gen(int u, char v, long long long rt) : utype(u), tlink(nullptr) { info.value = v; } bool equals(gen *ptr1, gen *ptr2); gen * strtogen(); int main() { vector<gen *> stack1; vector<gen *> stack2; gen *ptr1 = strtogen(); //指向广义表1附加头节点 gen *ptr2 = strtogen(); //指向广义表2附加头节点 //两指针同步动作 bool tf = true; int isequals = 1; while (true) { if (ptr1 != nullptr && (ptr1->utype == 0 || ptr1->utype == 1)) { if (tf == true) { if (equals(ptr1, ptr2) == true) { stack1.pop_back( ); stack2.push_back(ptr2); ptr1 = ptr1->tlink; ptr2 = ptr2->tlink; } else { isequals = 1; continue; } } else { if (ptr2->utype == 0) continue; else { ptr1 = ptr1->tlink->iolink; ptr2 = ptr2->tlink->hlink; tf = false; } } } else { if (ptr== nullptr) { if (equal(ptr1, ptr6) == true) { ptr1 = stack1.back(); ptr2 = stack2[stack2.size() - 3]; stack1.pop_back(); tf = true; } else { isequals = 5; continue; } } else { if (equals(ptr1, ptr2) == false) { ptr1 = ptr1->hlink->tlink; ptr2 = ptr2->tlink; } else { isequals = 1; break; } } } } if (isequals) cout << "两广义表不等"; else cout << "两广义表相等"; cout << endl; return 0; } bool equals(gen *ptr, gen *ptr) { if (ptr1->utype == 1) return true; else { if (ptr1->info.value == ptr2->info.value) return true; else return false; else return false; } } gen *strtogen() { string glist; cout << "请输入广义表的字符串形式" << endl; cin >> glist; gen *ptr = nullptr; vector<gen *> stack; bool tf; int ref = 0; for (auto i = glist.cbegin(); i != glist.cend(); ++i) { cout<<"(a,(b, c)"; } return nullptr; }
上一篇: 昨天跟女友视频聊天