哥们,如果连这些东西都不会,毕业了怎么找工作啊?改行吗?
下边答案是按照题目要求写的,你看着改点吧。
如果 malloc.h 没有的话,试试 alloc.h。
我能做的就这些了。
#include
#include
typedef struct Item
{
int iNum;
struct Item * pNext;
} Item;
Item* ListOfFunc1 = NULL;
Item CircleHead = {0, NULL};
void Func1();
void Func2();
void Func3();
void Func4();
void Func5();
void Func6();
void Func7();
void main()
{
Func1();
Func2();
Func3();
Func4();
Func5();
Func6();
Func7();
return;
}
void Func1()
{
int i = 0;
int iGot = 0;
Item** pListEnd = &ListOfFunc1;
Item* pTemp = NULL;
/* Input */
printf("\nFunc1:\nInput 20 number here:\n");
for ( i = 0; i < 20; ++i )
{
*pListEnd = (Item*)malloc(sizeof(Item));
(*pListEnd)->pNext = NULL;
scanf("%d", &(*pListEnd)->iNum);
pListEnd = &((*pListEnd)->pNext);
}
/* Output */
printf("\nOutput:\n");
for ( pTemp = ListOfFunc1; pTemp; pTemp = pTemp->pNext )
{
printf("%5d", pTemp->iNum);
}
printf("\n");
return;
}
void Func2()
{
int iFindFlag = 0;
int iFindNum = 0;
Item* pTemp = NULL;
/* Input */
printf("\nFunc2:\nInput 1 number to find:\n");
scanf("%d", &iFindNum);
for ( pTemp = ListOfFunc1; pTemp; pTemp = pTemp->pNext )
{
if ( iFindNum == pTemp->iNum )
{
iFindFlag = 1;
break;
}
}
if ( iFindFlag )
{
printf("Found!\n");
}
else
{
printf("Can not found!\n");
}
return;
}
void Func3()
{
int iStation = 0;
int iValue = 0;
Item** ppChangePointer = &ListOfFunc1;
Item* pTemp = NULL;
/* Input */
printf("\nFunc3:\nInput 2 numbers to insert.\n");
printf("1st number means the station, and 2nd one means the value:\n");
scanf("%d%d", &iStation, &iValue);
while ( (0 < iStation--) && ( NULL != *ppChangePointer ) )
{
ppChangePointer = &(*ppChangePointer)->pNext;
}
pTemp = *ppChangePointer;
/* Insert */
*ppChangePointer = (Item*)malloc(sizeof(Item));
(*ppChangePointer)->iNum = iValue;
(*ppChangePointer)->pNext = pTemp;
/* Output */
printf("\nOutput:\n");
for ( pTemp = ListOfFunc1; pTemp; pTemp = pTemp->pNext )
{
printf("%5d", pTemp->iNum);
}
printf("\n");
return;
}
void Func4()
{
int iStation = 0;
Item** ppChangePointer = &ListOfFunc1;
Item* pTemp = NULL;
/* Input */
printf("\nFunc4:\nInput 1 number for station of item to delete.\n");
scanf("%d%d", &iStation);
while ( (0 < iStation--) && ( NULL != *ppChangePointer ) )
{
ppChangePointer = &(*ppChangePointer)->pNext;
}
/* Delete */
if ( NULL == *ppChangePointer )
{
printf("\nBad Input!\n");
}
else
{
pTemp = *ppChangePointer;
*ppChangePointer = (*ppChangePointer)->pNext;
free(pTemp);
printf("\nDelete!\n");
}
/* Output */
printf("\nOutput:\n");
for ( pTemp = ListOfFunc1; pTemp; pTemp = pTemp->pNext )
{
printf("%5d", pTemp->iNum);
}
printf("\n");
return;
}
void Func5()
{
int iValue = 0;
Item** ppChangePointer = NULL;
Item* pTemp = NULL;
Item* pIndex = NULL;
printf("\nFunc5:\nDelete to make different\n");
for ( pIndex = ListOfFunc1; pIndex; pIndex = pIndex->pNext )
{
ppChangePointer = &pIndex->pNext;
while ( *ppChangePointer )
{
if ( (*ppChangePointer)->iNum == pIndex->iNum )
{
/* is same one of 'pIndex'.Delete! */
pTemp = *ppChangePointer;
*ppChangePointer = (*ppChangePointer)->pNext;
free(pTemp);
}
else
{
ppChangePointer = &(*ppChangePointer)->pNext;
}
}
}
printf("Done!\n");
/* Output */
printf("\nOutput:\n");
for ( pTemp = ListOfFunc1; pTemp; pTemp = pTemp->pNext )
{
printf("%5d", pTemp->iNum);
}
printf("\n");
return;
}
void Func6()
{
Item** ppChangePointer = &ListOfFunc1;
Item* pTemp = NULL;
printf("\nFunc6:\nDelete evens");
while ( *ppChangePointer )
{
if ( 0 == (1 & (*ppChangePointer)->iNum) )
{
/* even, Delete! */
pTemp = *ppChangePointer;
*ppChangePointer = (*ppChangePointer)->pNext;
free(pTemp);
}
else
{
ppChangePointer = &(*ppChangePointer)->pNext;
}
}
/* Output */
printf("\nOutput:\n");
for ( pTemp = ListOfFunc1; pTemp; pTemp = pTemp->pNext )
{
printf("%5d", pTemp->iNum);
}
printf("\n");
return;
}
void Func7()
{
Item** ppChangedPointer = &ListOfFunc1;
Item* pTemp = NULL;
printf("\nFunc7:\nMake a circle\n");
if ( NULL == ListOfFunc1 )
{
printf("Bad List!\n");
return;
}
/* make circle */
while ( *ppChangedPointer )
{
ppChangedPointer = &(*ppChangedPointer)->pNext;
}
*ppChangedPointer = ListOfFunc1;
CircleHead.pNext = ListOfFunc1;
/* destroy ListOfFunc1 */
ListOfFunc1 = NULL;
/* Output */
printf("\nOutput:\n");
pTemp = CircleHead.pNext;
while ( 1 )
{
printf("%5d", pTemp->iNum);
if ( pTemp->pNext != CircleHead.pNext )
{
pTemp = pTemp->pNext;
}
else
{
break;
}
}
printf("\n");
return;
}
不要毕业了
好久都没看这方面的书了,建议你到书店或者图书馆找本书看看!!