初学者 麻烦各位帮忙找错!谢谢
1插入元素#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 10
#define NUM 10
typedef struct{
int *elem;
int length ;
int listsize;
}SqList;/*P22*/
int InitList(Sqlist *L){
L->elem=(int*)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L->elem) exit(OVERFLOW);
L->length=0;
L->listsize=LIST_INIT_SIZE;
return OK;
}/*P23*/
void GreatList_L(LinkList&L,int n){
struct LNode *p;int i;
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
for(i=n;i>0;--i){
p=(LinkList)malloc(sizeof(LNode));
scanf("%d",&p->data);
p->next=L->next;L->next=p;
}
}/*P30*/
int ListInsert_L(LinkList&L,int i,int e){
struct LNode *next,*p,*s;int j;
p=L;j=0;
while(p&&j<i-1){p=p->next;++j;}
if(!p||j>i-1)return ERROR;
s=(LinkList)malloc(sizeof(LNode));
s->data=e;s->next=p->next;
p->next=s;
return OK;
}/*P29*/
main()
{
Sqlist L;
int i,e;
InitList_Sq(&L);
printf("input list:\n");
GreatList_L(&L,NUM);
printf("input the position and the number:\n");
scanf("%d,%d",&i,&e ) ;
ListInsert_L(&L,i,e);
printf("new list:\n");
print(&L);
getch();
}
2删除元素
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 10
#define NUM 10
typedef struct{
int *elem;
int length ;
int listsize;
}Sqlist;/*P22*/
int InitList(Sqlist *L){
L->elem=(int*)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L->elem) exit(OVERFLOW);
L->length=0;
L->listsize=LIST_INIT_SIZE;
return OK;
}/*P23*/
void GreatList_L(LinkList&L,int n){
struct LNode *p;int i;
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
for(i=n;i>0;--i){
p=(LinkList)malloc(sizeof(LNode));
scanf("%d",&p->data);
p->next=L->next;L->next=p;
}
}/*P30*/
int ListDelete_L(LinkList& L,int i,int e){
struct *next,*p,*q;int j;
p=L;j=0;
while(p->next&&j<i-1){
p=p->next;++j;
}
if(!(p->next)||j>i-1) return ERROR;
q=p->next;p->next=q->next;
e=q->data;free(q);
return OK;
}/*P30*/
main()
{
Sqlist L;
int i,*e;
InitList_Sq(&L);
printf("input list :\n");
GreatList_L(&L,NUM);
printf("input the position:\n");
scanf("%d",&i);
ListDelete_L(&L,i,e);
printf("new list:\n");
print(&L);
getch();
}
3栈进制数转换
#include<stdio.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -1
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define MAXQSIZE 10
typedef int ElemType;
typedef struct{
int *base;
int *top;
int stacksize;
}SqStack;
/*
void InitStack(SqStack &S){
S->base=(int*)malloc(STACK_INIT_SIZE*sizeof(int));
if(!S->base)
{exit(OVERFLOW);
}
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
return OK;
} */
void InitStack(LStack S,SElemType&e){
S=NULL;
return OK;
}
void StackEmpty(SqStack &S){
if(S->top==S->base)
return OK;
else
return ERROR;
}
void Push(LStack &S,SElemType e){
LStack p;
p=(LStack*)malloc(sizeof(SNode));
if(!p)exit(OVERFLOW);
p->data=e;
p->next=S;
S=p;
return OK;
}
void Pop(LStack &S,SElemType &e){
LStack p;
if(!S)return ERROR;
e=S->data;
p->S;
S=p->next;
free(p);
return OK;
}
void conversion(){
InitStack(S);
scanf("%d",N);
while(N){
Push(S,N%8);
N=N/8;
}
while(!StackEmpty(S)){
Pop(S,e);
printf("%d",e);
}
}
void main()
{
int N,r;
printf("input the number:");
scanf("%d",&N);
printf("jinzhi:");
scanf("%d",&r);
printf("the number is:\n");
conversation(N,r);
getch();
}