首先要明确有三类结点:未删除的结点、已删除的结点、无效结点。 (1)定义静态链表。 ——order变量表示结点在链表上的序号,最后需要先输出所有未删除的结点,然后输出所有被删除的结点,因此可在后面令未删除的结点的order从0开始编号,被删除的结点的order从maxn开始编号。 (2)初始化。令order的初值均为2 maxn——...
ListNode*preHead = head; ListNode*newList = new ListNode(-1, -1); ListNode*newListHead = newList; while (head != NULL) { if (exist[abs(head->val)]) { preHead->next = head->next; newList->next = head;// newList = newList->next;//newList现在指向head head = preHead->next...
if(record[abs(data[add].key)]>1)//absolute value绝对值 remoList.push_back(data[add]); else newList.push_back(data[add]); add=data[add].next; } if(newList.size()>0){ for(inti=0;i<newList.size()-1;i++) printf("%05d %d %05d\n",newList[i].add,newList[i].key,newList[...
PAT_甲级_1097 Deduplication on a Linked List 题目大意: 给定一条单链表,要求分解为两条链表,第一条是去除绝对值重复数值结点的链表,第二条是去除的结点组成的链表 算法思路: 首先使用node存储所有输入的节点,removed存储需要删除的节点。由于需要判断node中的节点是否需要删除,我们使用isExist表示与该节点数据的绝对...
p = sLinkList[p].next; }while(p!=-1); } intmain(){ // freopen("Data.txt","r",stdin); kHead = rHead = -1; Read(); // OutPut(kHead); // puts("~~~分界线~~~"); DeDuplication(); OutPut(kHead); OutPut(rHead);
1097. Deduplication on a Linked List (25) [链表] Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of which the value or absolute value of its key equals ...
("%d",&a);scanf("%d%d",&node[a].key,&node[a].next);node[a].address=a;}for(inti=begin;i!=-1;i=node[i].next){if(exist[abs(node[i].key)]==false){exist[abs(node[i].key)]=true;node[i].num=cnt1;cnt1++;}else{node[i].num=maxn+cnt2;cnt2++;}}sort(node,node+maxn...
PAT 甲级 1097 Deduplication on a Linked ListAAA专业手机贴膜小张 立即播放 打开App,流畅又高清100+个相关视频 更多187 -- 9:24 App PAT 甲级 1074 Reversing Linked List 40 -- 8:43 App PAT 甲级 1133 Splitting A Linked List 3296 6 13:26 App pta 7-3判断上三角矩阵 142 1 13:25 App pat...
Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of which the value or absolute value of its key equals K will be kept. At the mean time, all the removed...
#include<iostream>#include<vector>usingnamespacestd;structnode{intkey,next;}n[100000];intmain(){inti,j,k;inthead,N;cin>>head>>N;while(N--){cin>>i>>j>>k;//i地址;j数据;k为nextn[i].key=j;n[i].next=k;}//输入数据boolappeared[100000]={0};vector<int>v1,v2;for(i=head;i>...