马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 夙惜言 于 2020-11-16 19:41 编辑
感觉自己快忘干净了,一直报错:
In function 'main':
[Error] expected declaration specifiers or '...' before '&' token
[Error] expected declaration specifiers or '...' before numeric constant
附上原码:#include <stdio.h>
#include <stdlib.h>
typedef int ElemType;
//¹ØÓÚElemType:ËüÊÇelement type£¨¡°ÔªËصÄÀàÐÍ¡±£©µÄ¼ò»¯Ìå¡£
//¿ÉÒÔÊÇÈκÎÊý¾ÝÀàÐÍ£¬ÕâÀïÊÇintÐÍ
typedef struct Node
{
int data;
struct Node * next;
}Node;
typedef struct Node* LinkList;
//link:Á´½Ó list:Ŀ¼
int GetElem (LinkList L,int i,int *e);
//·µ»ØÁ´±íLµÚi¸öÊý¾Ý
int ListInsert (LinkList L,int i,int e);
//½«ÔªËØe²åÈëÁ´±íLµÄµÚi¸öλÖÃ
int ListDelete (LinkList L,int i,int *e);
//ɾ³ýÁ´±íLµÄµÚi¸öλÖõÄÊýÖµ£¬²¢ÓÃe·µ»ØÆäÖµ
LinkList CreateListHead ();
//´´½¨Ò»¸öÁ´±í¡ª¡ªÍ·²å·¨
int main (void)
{
LinkList *L;
LinkList CreateListHead(&L,3);
return 0;
}
int GetElem (LinkList L,int i,int *e)
{
int j;
LinkList p = L->next;
for(j = 1 ; p && j <= i ; j++)
//°É¡®p¡¯·ÅÔÚÅж¨½á¹ûÀÈç¹û¡®p¡¯ÎªNULL£¬ÄÇô¡®&&¡¯·µ»ØΪ0£¬³ÌÐò½áÊø
//ÕâÑùµÄºÃ´¦¾ÍÊÇÊ¡È¥ÁËÒ»´ÎifÅж¨
{
p = p->next;
}
if( !p || j>i )
{
return 0;
}
*e = p->data;
return 1;
}
int ListInsert (LinkList L,int i,int e)
{
int j;
LinkList _new;
LinkList p = L->next;
while( p && j<i )
{
p = p->next;
j++;
}
if( !p || j>i )
{
return 0;
}
_new = (LinkList)malloc(sizeof(Node));
_new->data = e;
_new->next = p->next;
p->next = _new;
return 1;
}
int ListDelete (LinkList L,int i,int *e)
{
int j;
LinkList p = L;
for(j = 0 ; j < i && p ; j++)
{
p = p->next;
}
if( !(p->next) || j>i )
{
return 0;
}
p = p->next->next;
*e = p->next->data;
free(p->next);
return 1;
}
LinkList CreateListHead( LinkList *L,int number )
{
LinkList p;
int newdata;
(*L) = (LinkList)malloc(sizeof(Node));
(*L)->next = NULL;
for( int i = 1; i < number ; i++ )
{
p = (LinkList)malloc(sizeof(Node));
scanf("%d",&newdata);
p -> data = newdata;
p -> next = (*L)->next;
(*L) -> next = p;
}
}
|