- packagecom.eshore.sweetop.dataframe;
- publicclassMyLinkedList{
- privateElementhead;
- publicvoidinsert(intx){
- Elemente=newElement(x);
- e.next=head;
- if(head!=null){
- head.pre=e;
- }
- head=e;
- e.pre=null;
- }
- privateElementsearch(intk){
- Elemente=head;
- while(e!=null&&e.key!=k){
- e=e.next;
- }
- returne;
- }
- privatevoiddelete(intx){
- Elemente=search(x);
- if(e.pre!=null){
- e.pre.next=e.next;
- }else{
- head=e.next;
- }
- if(e.next!=null){
- e.next.pre=e.pre;
- }
- }
- publicStringtoString(){
- StringBuildersb=newStringBuilder();
- sb.append("[");
- Elemente=head;
- while(e!=null){
- sb.append(e.key);
- sb.append(",");
- e=e.next;
- }
- sb.setCharAt(sb.length()-1,']');
- returnsb.toString();
- }
- privateclassElement{
- privateElementpre;
- privateElementnext;
- publicintkey;
- publicElement(intx){
- this.key=x;
- }
- }
- publicstaticvoidmain(String[]args){
- MyLinkedListlist=newMyLinkedList();
- list.insert(3);
- list.insert(6);
- list.insert(4);
- list.delete(6);
- System.out.println(list);
- }
- }