当前位置:网站首页>Linked list de duplication
Linked list de duplication
2022-06-11 05:03:00 【bolite】
3-2-1 Linked list The chain watch is weightless (25 branch )
Given a linked list with integer keys L, You need to delete the key node where the absolute value is repeated . For each key value K, Only the first absolute value is equal to K The nodes of are reserved . meanwhile , All deleted nodes must be saved in another linked list . For example, given L by 21→-15→-15→-7→15, You need to output the list after de duplication 21→-15→-7, And the deleted list -15→15.
Input format :
Enter... On the first line L The address of the first node and a positive integer N(≤1e5, Is the total number of nodes ). The address of a node is nonnegative 5 An integer , Empty address NULL use -1 To express .
And then N That's ok , Each line describes a node in the following format :
Address Key value Next node
Where the address is the address of the node , The key value is an absolute value that does not exceed 10
4
The integer of , The next node is the address of the next node .
Output format :
First output the list after de duplication , Then output the deleted list . Each node occupies a row , Output... In input format .
sample input :
00100 5
99999 -7 87654
23854 -15 00000
87654 15 -1
00000 -15 99999
00100 21 23854
sample output :
00100 21 23854
23854 -15 99999
99999 -7 -1
00000 -15 87654
87654 15 -1
Code display ( Linked list version ):
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<malloc.h>
#define N 100010
struct LNode {
int idex;// The address of the node
int data;// The data of this node
int nextidex;// The address of the next node
struct LNode* next;
};
typedef struct LNode* List;
int main()
{
int a[N] = {
0 };// Record address data
int b[N] = {
0 };// Record repetition
int c[N] = {
0 };// Record the next address
int n;// Make a cycle
int m;// Header
int zb;// to b Array positioning
int cb;// to a Array positioning
int sb;// save data Of
scanf("%d %d", &m, &n);
int i = 0;
for (i = 0; i < n; i++) {
scanf("%d %d %d", &zb, &sb, &cb);
a[zb] = sb;
c[zb] = cb;
// b[abs(sb)]++;
}
if (n == 1) {
printf("%05d %d -1", zb, sb);
return 0;
}
if (n == 0) {
return 0;
}
int aim = m;
List head, tail, p1, tou, wei;
//head For the linked list after weight removal ,tou For a list of repeated numbers
//tail Is the tail pointer of the linked list after de duplication ,wei Is the tail pointer of the linked list with repeated numbers
head = tail = p1 = tou = wei = NULL;
for (aim = m; aim != -1; aim = c[aim]) {
p1 = (List)malloc(sizeof(struct LNode));
p1->idex = aim;
p1->data = a[aim];
p1->nextidex = c[aim];// Buckle the contents of the node on the structure
if (b[abs(p1->data)]) {
if (tou == NULL) {
tou = p1;
}
else {
wei->next = p1;
wei->nextidex=p1->idex;
}
wei = p1;
}
else {
b[abs(p1->data)]++;
if (head == NULL) {
head = p1;
}
else {
tail->next = p1;
tail->nextidex=p1->idex;
}
tail = p1;
}
}
List L, l;
L = head;
l = L->next;
while (l) {
// Output the linked list without repetition
printf("%05d %d %05d\n", L->idex, L->data, L->nextidex);
L = l;
l = l->next;
}
printf("%05d %d -1\n", L->idex, L->data);
L=tou;
l=L->next;
if (tou) {
// Output duplicate digital linked list
while (l) {
printf("%05d %d %05d\n", L->idex, L->data, L->nextidex);
L = l;
l = l->next;
}
printf("%05d %d -1\n", L->idex, L->data);
}
}
The following is an illustration of the processing of the input address 
边栏推荐
- 免费数据 | 新库上线 | CnOpenData全国文物商店及拍卖企业数据
- 博途仿真时出现“没有针对此地址组态任何硬件,无法进行修改”解决办法
- codesys 獲取系統時間
- Conversion relationship between coordinate systems (ECEF, LLA, ENU)
- Database introduction
- [Transformer]MViTv2:Improved Multiscale Vision Transformers for Classification and Detection
- Technology | image motion drive interpretation of first order motion model
- Oh my Zsh correct installation posture
- oh my zsh正确安装姿势
- 一大厂95后程序员对部门领导不满,删库跑路被判刑
猜你喜欢

2021 iccv paper sharing - occlusion boundary detection

Win10+manjaro dual system installation

New library goes online | cnopendata immovable cultural relic data

Yolact paper reading and analysis

RGB image histogram equalization and visualization matlab code

Free data | new library online | cnopendata data data of national heritage stores and auction enterprises

AAAI2022-ShiftVIT: When Shift Operation Meets Vision Transformer

博途仿真时出现“没有针对此地址组态任何硬件,无法进行修改”解决办法

Pychart displays pictures with imshow

Sealem Finance打造Web3去中心化金融平台基础设施
随机推荐
Ican uses fast r-cnn to get an empty object detection result file
Free data | new library online | cnopendata data data of national heritage stores and auction enterprises
华为设备配置MCE
Introduction to coordinate system in navigation system
Real time update of excellent team papers
[Transformer]MViTv1:Multiscale Vision Transformers
Tips and websites for selecting papers
SAVING AND LOADING A GENERAL CHECKPOINT IN PYTORCH
MySQL regularly deletes expired data.
Share 𞓜 jointly pre training transformers on unpaired images and text
go MPG
Powerful new UI installation force artifact wechat applet source code + multiple templates support multiple traffic main modes
[Transformer]MViTv2:Improved Multiscale Vision Transformers for Classification and Detection
Tianchi - student test score forecast
How to choose a suitable optical network card?
NVIDIA SMI has failed because it could't communicate with the NVIDIA driver
C language test question 3 (program multiple choice question - including detailed explanation of knowledge points)
The solution "no hardware is configured for this address and cannot be modified" appears during botu simulation
MySQL nested sorting: first sort and filter the latest data, and then customize the sorting of this list
Temporary website English Writing