12.設計一個整型鏈表類list,可以實現鏈表節點的插入(insert)、刪除(delete),以及鏈表數據的輸出操做(print)ios
#include<iostream> using namespace std; class intLinkList{ private: int *list; int size; int length; public: intLinkList(int s){ list = new int[s]; size=s; length = 0; } int insert(int location, int data){ if(location<1 || location>length+1 || length>=size) return 0; // 插入失敗 for(int i=length; i>location; i--){ list[i]=list[i-1]; } list[location-1]=data; length++; return 1; // 插入成功 } int delet(int location){ if(location<1 || location>length || length<=0) return 0; for(int i=location; i<length; i++){ list[i-1]=i; } length--; return 1; } int getElem(int location){ if(location<1 || location >length) return 0; return list[location-1]; } }; int main(){ intLinkList list1(100); list1.insert(1,1); list1.delet(1); cout<<list1.getElem(1); }