Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by 1 ( 16 years ago )
#include "stdafx.h"
#include "stdlib.h"
#include "time.h"

typedef struct LIST
{
int Object;
struct LIST *Next;
} LIST;

int LAdd(LIST **Item, int Object) {
LIST *NewItem;
int Result = 1;

if(Item == NULL) {
printf("Error argument function LAdd\n
exit(1);
}
NewItem = new LIST;
if(NewItem != NULL) 
{
NewItem->Object = Object;
if(NULL == *Item) {
NewItem->Next = NULL;
*Item = NewItem;
}
else {
NewItem->Next = (*Item)->Next;
(*Item)->Next = NewItem; 
}
}
else
{
Result = 0;
}

return Result;
}

int LAppend(LIST **Item, int Object{
int Result = 1;
LIST *EndSeeker;

if(Item == NULL) {
printf("Error argument function LAppend\n");
exit(1);
}

if (NULL == *Item)
{
Result = LAdd(Item, Object);
}
else
{
EndSeeker = *Item;
while(EndSeeker->Next != NULL)
{
EndSeeker = EndSeeker->Next;
}
Result = LAdd(&EndSeeker;, Object);
}

return Result;
}

LIST *LDeleteThis(LIST *Item
{
LIST *NextNode = NULL;

if(Item != NULL)
{
NextNode = Item->Next;
delete Item;
}

return NextNode;
}

void LDeleteNext(LIST *Item{
if(Item != NULL && Item->Next != NULL)
{
Item->Next = LDeleteThis(Item->Next);
}
}

void LDelIt(LIST **Item, int Object)
{
if(*Item!=NULL)
{
LIST *p = NULL;

p=*Item;
printf("\n");
printf("Vvedite Object:");
scanf("%d",&Object;);

while(p != NULL)
{
while(p->Next != NULL && p->Next->Object == Object)
{
LDeleteNext(p);
}
p=p->Next;
}

}
else
{
printf("\nPeredan pustoi spisok!\n");
exit(1);
}

}

int _tmain(int argc, _TCHAR* argv[])
{
LIST *List = NULL, *p;
int Length = 0;
srand(unsigned(time(NULL)));
for(Length = 1; Length < 16; Length++){
LAppend(&List;, rand()%5); 

}
p = List;

while(p != NULL)
{
printf("%d ", p->Object);
p = p->Next;
}

//List = NULL;
LDelIt(&List;,Length);

p = List;
while(p != NULL)
{
printf("%d ", p->Object);
p = p->Next;
}
printf("\n");

return 0;
}

 

Revise this Paste

Parent: 14684
Your Name: Code Language: