pins
#include <bits/stdc++.h>
using namespace std;
int main()
{
int *p;
int a = 0, b = 1, c = 10;
p = &a;
cout << endl << *p;
*p = b;
a = 100;
cout << endl << *p;
cout << endl << a;
p = &c;
cout << endl << c;
return 0;
}
// output: 0 100 100 10
链表
#include <bits/stdc++.h>
using namespace std;
struct node
{
int id;
node *next;
};
int main()
{
// head
node *head = new node;
head->next = 0;
// build linked list
node *t = head;
int n;
scanf("%d", &n);
for(int i=0; i<n; i++)
{
node *p = new node;
// 新建一个临时的node
p->id = i;
// 为该node赋值
p->next = 0;
// 如果是最后一个的话,next为0,作为尾结点的标志
t->next = p;
// 将t的next设为p,本质上是将上一次循环中的p的next设置为当前的p,是连接链表元素的一条语句
t = p;
// 此时t的指向当前的p
}
t = head->next;
while(t->next!=0)
{
cout << t->id << ' ';
t = t->next;
}
cout << t->id;
return 0;
}
↑ 心里几把
others:
#include <algorithm>
list<int> a;
stack<int> a;
queue<int> a;
priority_queue<int> a; //优先队列
deque<int> a; // 双端队列
vector<int> a;
set<int> a; // 红黑树实现
multiset<int> a; // 红黑树实现
map<int, string> a; // 红黑树实现 key -> value / 一一对应
multimap<int, string> a;// 一对多