联发科嵌入式C++写法

刚接触c++一个月,没学过c,就用c++写了,写的很麻烦,就记录一下

#include <algorithm> 
#include <cstdarg>
#include <cstdlib>
#include <ctime>
#include <initializer_list>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <unordered_map>
#include <functional>
#include <sstream>

using std::begin;
using std::cin;
using std::cout;
using std::end;
using std::endl;
using std::initializer_list;
using std::istringstream;
using std::map;
using std::max;
using std::pair;
using std::set;
using std::string;
using std::stringstream;
using std::unordered_map;
using std::vector;
struct node {
  int data;
  node *next;
  node *pre;
};
void printChain(node *L) {
  if (L == NULL) {
        printf("error");
  }
  while (L != NULL) {
    cout data << " ";
    L = L->next;
  }
  cout << endl;
}
node *create(vector Array) { 
  node *p, *pre, *head;
  head = new node;
  head->pre = NULL;
  head->next = NULL;
  pre = head;
  for (int i = 0; i != Array.size(); ++i) {  // 构建双向链表
    p = new node;
    p->data = Array[i];
    p->next = NULL;
    p->pre = pre;
    pre->next = p;
    pre = p;
  }
  return head;
}
int main() {
  int num;
  string s1, s2, s3;
  vector chain;
  node *head = new node;
  node *n = new node;
  while (getline(cin, s1)) {
    getline(cin, s2);
    istringstream ss1(s1);
    while (ss1 >> s3) {
      chain.push_back(atoi(s3.c_str()));
    }
    num = atoi(s2.c_str());
    node *L = create(chain);
    head = L;
    L = L->next;
    if (num data) {
      n->data = num;
      n->next = L;
      head->next = n;
      n->pre = head;
      L->pre = n;
    }
    else if (num >= L->data){
      while (L->next != NULL) {
        if (num >= L->data) {
          L = L->next;
        }
        else {
          n->data = num;
          n->next = L;
          L->pre->next = n;
          n->pre = L->pre;
          L->pre = n;
          break;
        }
      }
      if (L->next == nullptr && num >= L->data) {
          n->data = num;
          n->next = nullptr;
          n->pre = L;
          L->next = n;
      }
      else if (L->next == nullptr && num data) {
        n->data = num;
        n->next = L;
        L->pre->next = n;
        n->pre = L->pre;
        L->pre = n;
      }

    }
    printChain(head->next);
    chain.clear();
  }
  return 0;
}
#笔试题目##MTK联发科技#
全部评论
刚学一个月就这么厉害
点赞 回复
分享
发布于 2021-07-21 15:33
大佬,用c把图片在开发板上实现从上往下输出怎么操作?从下往上输出就可以实现,但是改参数后,输出的图片就失真了
点赞 回复
分享
发布于 2021-07-22 11:32
联想
校招火热招聘中
官网直投

相关推荐

点赞 4 评论
分享
牛客网
牛客企业服务