#include
#include
using namespace std;
typedef struct Node{
int data;
struct Node *next;
}*LinkList;
int Get_Length(LinkList list){
LinkList temp;
temp=list;
int k=0;
for(;temp->next;){
temp=temp->next;
// cout<
}
cout<<"The linklist length is: "<
};
void Show_LinkList(LinkList list){
for(;list->next;){
list=list->next;
cout<
}
}
Node *Get_By_value(LinkList list,int value){
for(list=list->next;list->next;){
if (list->data==value)
return list;
list=list->next;
}
return list;
};
Node *Get_By_Index(LinkList list,int index){ //
int k=0;
for(list=list->next;list->next && k
list=list->next;
}
return list;
};
Node *Insert(LinkList list,int index,int value){
Node *location,*temp,*node;
location=Get_By_Index(list,index-1);
temp=location->next;
node=(Node *)malloc(sizeof(Node));
node->data=value;
location->next=node;
node->next=temp;
return list;
}
Node *Delete_By_Index(LinkList list,int index){
Node *temp;
temp=Get_By_Index(list,index-1);
temp->next=temp->next->next;
return list;
}
int main(){
Node *node,*temp;
temp=(Node*)malloc(sizeof(Node));
temp->next=NULL;
LinkList list;
list=temp;
for(int i=0;i<10;i++){
node=(Node*)malloc(sizeof(Node));
node->data=i;
node->next=NULL;
temp->next=node;
temp=node;
}
Get_Length(list);
list=Insert(list,3,100);
Get_Length(list);
list=Delete_By_Index(list,2);
Get_Length(list);
Show_LinkList(list);
getch();
return 1;
}
建议你看一下标准C++,C++标准库中这些都有。vector deque list