C,
pasted
on Jan 7:
|
#include<stdio.h>
#include<conio.h>
struct node
{
int Info;
struct node* pNext;
};
typedef struct node NODE;
typedef struct list
{
NODE* pHead;
NODE* pTail;
};
typedef struct list LIST;
void Init(LIST& L);
NODE* getNode(int x);
void addHead(LIST& L, NODE* new_ele);
void Input(LIST& L);
void Output(LIST L);
long Sum(LIST L);
void Init(LIST& L)
{
L.pHead = NULL;
L.pTail = NULL;
}
NODE* getNode(int x)
{
NODE* p;
p = new NODE;
if(p == NULL)
return NULL;
p->Info = x;
p->pNext = NULL;
return p;
}
void addHead(LIST& L, NODE* new_ele)
{
if(L.pHead == NULL)
{
L.pHead = new_ele;
L.pTail = L.pHead;
}
else
{
new_ele->pNext = L.pHead;
L.pHead = new_ele;
}
}
void Input(LIST& L)
{
int n;
printf("\nNhap so luong node: ");
scanf("%d", &n);
Init(L);
for(int i = 1; i <= n; i++)
{
int x;
printf("\nNhap 1 so nguyen: ");
scanf("%d", &x);
NODE* p = getNode(x);
addHead(L, p);
}
}
void Output(LIST L)
{
for(NODE* p = L.pHead; p != NULL; p = p->pNext)
{
printf("%4d", p->Info);
}
}
long Sum(LIST L)
{
long s = 0;
for(NODE*p = L.pHead; p != NULL; p = p->pNext)
{
s = s + p->Info;
}
return s;
}
int main()
{
LIST lst;
Input(lst);
Output(lst);
long kq = Sum(lst);
printf("\nTong cac node: %ld", kq);
getch();
return 0;
}
|
Output:
|
Line 17: error: conio.h: No such file or directory
Line 15: warning: useless storage class specifier in empty declaration
Line 18: error: expected ';', ',' or ')' before '&' token
Line 20: error: expected ';', ',' or ')' before '&' token
Line 21: error: expected ';', ',' or ')' before '&' token
Line 25: error: expected ';', ',' or ')' before '&' token
In function 'getNode':
Line 34: error: 'new' undeclared (first use in this function)
Line 34: error: (Each undeclared identifier is reported only once
Line 34: error: for each function it appears in.)
Line 34: error: expected ';' before 'NODE'
t.c: At top level:
Line 44: error: expected ';', ',' or ')' before '&' token
Line 58: error: expected ';', ',' or ')' before '&' token
In function 'Output':
Line 77: error: 'for' loop initial declaration used outside C99 mode
In function 'Sum':
Line 86: error: 'for' loop initial declaration used outside C99 mode
|
|