#include <iostream>
#include<malloc.h>
using namespace std;
typedef int E;
typedef struct Node{
E element;
struct Node *next;
}*node;
void initList(node nd){
nd->next=NULL;
}
void deleteDup(node nd) {
if (nd == NULL) return;
node current = nd;
while (current != NULL) {
node runner = current;
while (runner->next != NULL) {
if (current->element == runner->next->element) {
node tmp = runner->next;
runner->next = runner->next->next;
free(tmp);
} else {
runner = runner->next;
}
}
current = current->next;
}
}
void delteNode(node n){
n->next->next=n->next->next->next;
}
void insertNode(node head,E e){
//有这个循环就是尾插,否则就是头插
while(head->next!=NULL)
head=head->next;
// new一个node存我们要插入结点的数据
node nd=(node)malloc(sizeof(struct Node));
nd->element =e;
//令我们的nd指向head指向的地方 ,其实就是NULL
nd->next=head->next;
//再把head的指向改为nd
head->next=nd;
}
int getNode(node n){
int i =0;
if(n==NULL) return 0;
while(n->next!=NULL)
{
i++;
n=n->next;
}
return i;
}
void printList(node n,int num){
while(n->next!=NULL){
cout<<n->next->element;
if(n->next->next!=NULL)cout<<" ";
n=n->next;
}
cout<<endl;
}
int main(){
struct Node head;
initList(&head);
int n;
cin>>n;
for(int i =0;i<n;i++)
{
int temp;
cin>>temp;
insertNode(&head,temp);
}
deleteDup(&head);
printList(&head,n);
return 1;
}
标签:node,崔鹏题,交个,OJ,runner,nd,head,next,NULL
From: https://www.cnblogs.com/Happy-Eric-1/p/17919806.html