真爱无限的知识驿站

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

linux下练习 c++ 函数模版例子

code:

//函数模版使用
//函数模版标准不支持参数默认值
#include<iostream>
#include<cstring>
using namespace std;
template <typename T>
void sort(T* a,int n)//普通冒泡排序
{
bool changed;
do
{
changed=false;
for(int i=1;i<n;i++)
{
if(a[i]<a[i-1])
{
swap(a[i],a[i-1]);
changed=true;
}
}
--n;
}
while(changed);
}
template <>//模版特化
void sort(const char* a[],int n)//普通冒泡排序
{
bool changed;
do
{
changed=false;
for(int i=1;i<n;i++)
{
if(strcmp(a[i],a[i-1])<0)
{
swap(a[i],a[i-1]);
changed=true;
}
}
--n;
}
while(changed);
}
//template <typename T>
//void show(T t[],int n)
template <typename T,int n>
void show(T(&t)[n])
{
//int n=sizeof(t)/sizeof(t[0]);//算出t的个数
for(int i=0;i<n;i++)
cout<<t[i]<<' ';
cout<<endl;
}
template <typename T>
void show(T t)
{
cout<<t<<endl;
}
int main()
{
int a[5]={6,7,8,3,2};
sort(a,5);//函数模版会自动匹配,不需要显式指定类型
show(a);
double d=12.345;
show(d);
char c[5]={'b','f','k','d','a'};
sort(c,5);
show(c);
const char* ca[3]={"fc","ca","ab"};
sort(ca,3);
show(ca);
return 0;
}


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();  

    Linq to DataSet 与linq to entities 实现权限设置模块

    数据库(数据库名为test)中表的内容:

    linq to Entities,将查询语句转换为普通的SQL语句

    .Net Code:

                using (testEntities MyEntity = new testEntities())
                {
                    #region linq to entities 内容练习3
                    var result = from s in MyEntity.stuinfo
                                 where s.username == "pkm"
                                 select new
                                 {
                                     username=s.username,
                                     age=s.age
                                 };
                    var psql = result.GetType().GetMethod("ToTraceString").Invoke(result, null);//得到原始sql语句
                    
                    Console.WriteLine(psql);
                    #endregion
                }


    pkm的linq to Entities学习2

    .Net Code

                using (testEntities TestEntity = new testEntities())
                {
                    #region linq to entities 内容练习2
                    #region 父子关系表查询
                    /*
                    var maxScorePerClass = from s in TestEntity.stuinfo
                                           group s by s.classID into s1
                                           select new
                                           {
                                               classid = s1.Key,
                                               stuinfo = from s2 in s1
                                                         where s2.score == s1.Max(p => p.score)
                                                         select s2
                                           };


    安装android开发环境,并运行apk软件

    1、安装运行环境

    http://blog.csdn.net/webrobot/article/details/7304831     

    安装运行环境,不要嫌麻烦,一步一步跟着做就不麻烦了。

    << < 17 18 19 20 21 22 23 24 25 26 > >>

    Powered By Z-BlogPHP 1.7.3

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