链表的增删改查
#ifndef LINK_H_
#define LINK_H_
/*
*node struction
* */
struct stu
{
int number;
char name[13];
struct stu *next;
};
typedef struct stu stu_t;
typedef stu_t *stu_pointer;
/*
*function:init one node datas
return values:void
para
* */
void init_node(stu_pointer node);/*success*/
/*
*create a new link
* */
stu_pointer create_link();/*success*/
/*
*destroy one link which you have created
* */
void destroy_link(stu_pointer head);/*success*/
/*
*traversal one link which haved been created
* */
void print_link(stu_pointer head);/*success*/
/*
*find one node which value have given
* */
stu_pointer find_node(stu_pointer head,int data);/*success*/
/*
* delect one node which value hava given
* */
stu_pointer delect_node(stu_pointer head,int data);
/*
* insert one new node into the link
* */
stu_pointer insert_node(stu_pointer head,int position,int data,char *name);
/*
* update the node you wannt update
* */
void updata_node(stu_pointer head,int olddata,int newdata,char *newname);/*success*/
/*
*print the value of the node
* */
void print_value_node(stu_pointer node);/*success*/ #endif
#include
#include "link.h"
#include
#include
int main
(void)
{
#if 0
stu_t stu[3]={{34,"chenwei",NULL},\ {23,"xiaowei",NULL},\
{56,"tangsha",NULL}};
stu_pointer head,p;
p=head=&stu[0];
stu[0].next=&stu
[1];
stu[1].next=&stu[2];
while(p!=NULL){
printf("number:%
d\tname:%s\n",p->number,p->name);
p=p->next;
}
#endif
#if 0
printf("\n--------------\n");
stu_pointer head,node;
int data;
int newdata;
printf("please create link\n");
head=create_link();
printf("travel the
link\n");
print_link(head);
char newname[24];
/* printf("please input
position\n");
scanf("%d",&data);
printf("\nplease input new datas\n");
scanf("%d%s",&newdata,newname);
node=insert_node(head,data,newdata,newname);
print_link(node);*/
printf("\nplease input data which you want to delect\n");
scanf("%d",&data);
node=delect_node(head,data);
print_link(node);
/* printf
("\nplease input the value which you want to search\n");*/
/* scanf("%d",&data);
node=find_node(head,data);
print_value_node(node);
printf("\ntest
updata_node\n");
updata_node(head,data,5);
print_link(head);*/
/*
head=destroy_link(head);
if(head==NULL)
printf("seccuse\n");*/
#endif
#if
1
stu_pointer head,node;
int data,data1;
char newname[14];
printf
("\n----------------\n");
printf("create one link\n");
head=create_link();
printf("output the datas of the link\n");
print_link(head);
printf("please
input data you want to search\n");
scanf("%d",&data);
node=find_node
(head,data);
print_value_node(node);
printf("please input data you want to
delect\n");
scanf("%d",&data);
head=delect_node(head,data);
printf("the data
of link after you delect %d node\n",data);
print_link(head);
printf("please
input new node\n ");
scanf("%d%s",&data,newname);
printf("please input
position\n");
scanf("%d",&data1);
head=insert_node(head,data1,data,newname);
print_link(head);
printf("updata old datas\n");
scanf("%d%d%
s",&data1,&data,newname);
updata_node(head,data1,data,newname);
print_link(head);
printf("destroy link\n");
destroy_link(head);
#endif
return 0;
}
void
init_node(stu_pointer node)/*init the data of one node*/
{
int num;
/*char
*nm;*/
char nm[14];
scanf("%d%s",&num,nm);
node->number=num;
strcpy(node-
>name,nm);
node->next=NULL;
}
stu_pointer create_link()/*create one link*/
{
stu_pointer head=NULL,p=NULL,new;
while(1){/*create link for new data and insert the
link*/
new=malloc(sizeof(stu_t));
if(NULL==new){
printf("malloc failed\n");
}
init_node(new);
if(new->number==0){
free(new);
new=NULL;
break;
}
else{
if(head==NULL){/*the link
is empty link whe the value of head is NULL*/ p=head=new;/*p adn
head position at the first node*/
else{/*p
position at the second node and after nodes*/ p->next=new;
p=p->next;
}
}
}
return head;/*return the head of the link*/ }
void print_link(stu_pointer head)/*print
the datas of the link*/
stu_pointer p;
p=head;
while(p!=NULL){/*the
program end when the value of p is NULL*/ printf("num:%d\tname:%s\n",p-
>number,p->name);
p=p->next;
}
}
/*destroy the link when you do need
it*/
void destroy_link(stu_pointer head)
{
stu_pointer p;
p=head;
while(p!=NULL){
head=p->next;/*set the head position at next one*/
free(p);/*free one node*/
p=head;
}
}
/*find the node which
value is equal with data of argument
*and return the postion of the node found
* */
stu_pointer find_node(stu_pointer head,int data) {
stu_pointer p;
p=head;
while(p!=NULL){
if(p->number==data){
/* printf("find
success\n");*/
return p;
}
else{
p=p->next;
}
}
return p;
}
/*print the value of the node*/
void print_value_node(stu_pointer node) {
printf("num:%d\tname:%s\n",node-
>number,node->name);
}
/*
*update the value of the node into a new data
* */
void
updata_node(stu_pointer head,int olddata,int newdata,char *newname)
{
stu_pointer p;
p=find_node(head,olddata);
p->number=newdata;
strcpy(p-
>name,newname);
}
/*
*insert a new node into the link
* */
stu_pointer insert_node
(stu_pointer head,int position,int data,char *newname)
{
stu_pointer new,p,back;
new=malloc(sizeof(stu_t));/*malloc new space*/ new->number=data;
strcpy(new-
>name,newname);
p=back=head;
if(head->number==position){/*judge the head if not
the find node*/
new->next=back;
head->next=new;
}
else{/*judge the node if not other node *
* which is
middle node or end node*/
p=find_node(head,position);
back=p-
>next;
new->next=back;
p->next=new;
}
return head;
}
/*delect one old node if you need delect it
*you can use the function to delect one node
* */
stu_pointer delect_node(stu_pointer head,int data) {
stu_pointer p,back;
back=head;
if(head->number==data){
head=back->next;
free(back);
back=NULL;
return head;
}
else{
p=head->next;
数据库的增删改查(精)
学习收藏数据库增删改查 --查询信息系和计算机系的学生,并按学生所在系和学号排序。select sno,sname,Sdept from Student where Sdept='CS'OR Sdept='IS' order by Sdept,sno ASC --查询学生表中最小的年龄。 select MIN(sage from student --查询课程名中包含“数据”的课程名。 select cno,cname from course where Cname like'%数据%' --查询先行课程为空值的课程号、课程名及学分 select cno,cname,ccredit from Course where Cpno is null --查询李勇选修的数据库课程的成绩 select grade from SC where Sno=(select Sno from Student where Sname='李勇'and Cno=(select Cno from Course where cname='数据库' --查询平均成绩分以上的学生的学号 select distinct sno from SC scx where (select AVG(Grade from SC scy
where scy.sno=scx.Sno>85 --求计算机系没有选修数据库课程的学生姓名 select sname from Student where Sno not in(select Sno from SC where Cno in(select Cno from Course where Sname='数据库'and Sdept='IS' --求至少选修了学号为S1所选修的全部课程的学生学号 select distinct sno from SC scx where not exists(select*from SC scy where scy.Sno='20021522'and not exists(select* from sc scz where scz.sno=scx.sno and https://www.360docs.net/doc/0f11383681.html,o=https://www.360docs.net/doc/0f11383681.html,o --求各系的系的学生人数的,并将结果按学生人数的降序排序 select Sdept,COUNT(sno from Student group by Sdept order by Sdept ASC --查询选修了数学课程并且成绩高于该门课程平均分的学生学号和成绩 select sno,grade from SC scx where Grade>=(select AVG(Grade from SC scy where Cno=(select Cno from Course where Cname='数学'and Cno=(select Cno from Course
GridView的增删改查
GridView简单的增删改查,自己做了个小项目和大家分享,希望有所帮助 (PS:我也是刚学者,有好的学习方法大家一起学习哈~) 先来贴出本文代码运行的结果: 点击增加一行,第一行出现空格输入内容,点击确定增加,就可以将数据保存到数据库,并绑定到gridview中 点击编辑出现更新和取消,就可以直接在gridview上修改内容了 (PS:编号id是自动生成的,所以不可以修改,在这边让它成为只读的) 前端代码 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>