真爱无限的知识驿站

学习积累技术经验,提升自身能力

linux下练习 c++ 链表操作

code:

#include <iostream>
using namespace std;
typedef int T;
class List
{
struct Node
{
T data;
Node * next;
Node(const T&d=T()):data(d),next(0){}
};
Node * head;
public:
List():head(NULL)
{
cout<<"…list初始化完成…
";
}
void push_front(const T&d)//前插法
{
Node * p=new Node(d);
p->next=head;
head=p;
}
void push_behand(const T&d)//尾插法
{
Node *ph=head;
while(ph->next!=NULL) ph=ph->next;
Node * p=new Node(d);
ph->next=p;
}
void insert(const T&d,int pos)//任意位置插入
{
Node * p=new Node(d);
Node *& pn=getptr(pos);
p->next=pn;
pn=p;
/*
if(pos<=0)
{
    p->next=head;
    head=p;
}
else
{
Node * ph=head;
while(pos-->1 && ph->next !=NULL)
{
ph=ph->next;
}
p->next=ph->next;
ph->next=p;
}
*/
}
void remove(int pos)
{
if(pos<0) return ;
Node *& pn=getptr(pos);
Node *p=pn;
pn=pn->next;
delete p;
}
Node *& getptr(int pos)
{
if(pos<=0) return head;
Node * p =head;
while(pos-->1 && p->next !=NULL)
p=p->next;
return (*p).next; 
}
void travel()const//遍历
{
Node * p=head;
while(p!=NULL)
{
cout<<p->data<<' ';
p=p->next;
}
cout<<endl;
}
void clear()//清空内存
{
while(head != NULL)
{
Node *p=head->next;
delete head;
head=p;
}
}
~List()
{
clear();
cout<<"…内存释放完成…
";
}
};
int main()
{
List l;
l.push_front(5);
l.push_front(4);
l.push_front(7);
l.push_front(6);
l.push_behand(45);
l.push_behand(48);
l.insert(100,0);//小于0位置就插入到最前
l.insert(99,6);//插入到指定位置
l.insert(991,100);//大于最后位置就插入到最后
l.remove(1);
l.remove(0);
l.travel();
return 0;
}

 

linux学习与c编程2

    linux学习与c编程1

    sudo 在没有权限时,运行在命令前。  

      

    运行文件要用文件绝对路径,当前路径 要用 ./文件名   

      

    查看当前shell 用:ps  

    进入另一个 shell,直接输入shell的名字,如:ksh/tcsh/sh/bash/  

    退出一个shell 用 exit   

    切换shell,如: exec tsh   

    JAVA学习-Java集合框架介绍、ArrayList、LinkedList类的常见使用方法

    Java集合框架介绍

    所谓的框架就是一个类库的集合。集合框架就是一个用来表示和操作集合的统一的架构,它包含了实现集合的接口与类。

    集合框架中不同的集合类有各自不同的数据结构,所以在使用中要根据应用的性能要求来选择不同的集合类。

    集合类存放在java.util包中,今后进行程序编写时将大量使用集合类和相关接口。

    mvc中json格式的使用方法示例

    //View:   

    <script type="text/javascript">  

        $(document).ready(function() {  

            GetByJquery();  

    << 1 >>

    Powered By Z-BlogPHP 1.7.3

    Copyright 2024-2027 pukuimin Rights Reserved.
    粤ICP备17100155号