一): 不使用第三个变量,将两个变量a,b得值互换(不准用函数)
1) xor (<===异或???)
a =a xor b;
a =a xor b;
b =a xor b;
2) a+=b; b=a-b; a=a-b;
二) 不用任何条件语句求两个整形数的最大值?(不准用函数)?
max =a+b-|a-b|;
三)struct student {long ..; char .. float .. } 所占空间多大?
见struct 大小-
四)自己定义数据结构,写出程序:在一个单向链表中,往I位置插入一个节点。
#include <iostream.h>
#include <malloc.h>
#include <string>
typedef struct linklist{
int data;
struct linklist *next;
}Node,*LinkList;
/************************************************************************/
/* 链表的遍历显示 */
/************************************************************************/
void VisitLinkList(LinkList L)
{
LinkList v;
v=L->next;
if(!(v))printf("链表为空/n");
printf("/n头结点");
while(v)
{
printf("->%d",v->data);
v=v->next;
}
printf("/n完成链表遍历/n");
}
/************************************************************************/
/* 往I的位置后插入一个节点 */
/************************************************************************/
void InsertNode(LinkList &L,int i)
{
LinkList h,p;
h=L;
while(h&&(h->data!=i))
{
h=h->next;
}
if(h)
{
p=(LinkList )malloc(sizeof(Node));
//cout<<"input value for new node"<<endl;
//cin>>p->data;
p->data=88;
p->next=h->next;
h->next=p;
}else{
cout<<"i not found"<<endl;
}
}