Exemplo n.º 1
0
//Merge1
void MergeList1(SLinkList L)
{
	int n=10;
	int i=0;
	ElemType e;
	int j=0;

	InitList(L);
	printf("请输入A中数据的个数:");

	scanf("%d",&i);
	if(i>0)
		n=i;

	for(i=0;i<n;i++)
	{
loop:
		scanf("%d",&e);
		if(!LocateElem(L,e,compare))
			ListInsert(L,i+1,e);
		else
		{
			printf("已存在,请重新输入:");
			goto loop;
		}
	}
	printf("遍历链表");
	TraverseList(L,visit);
	printf("\n");

	printf("请输入B中数据的个数:");
	scanf("%d",&i);
	if(i>0)
		n=i;

	for(i=0;i<n;i++)
	{
		scanf("%d",&e);
		if(!(j=LocateElem(L,e,compare)))
		{
			ListInsert(L,ListLength(L)+1,e);
		}
		else
		{
			ListDelete(L,j,e);
		}
	}

	printf("遍历链表");
	TraverseList(L,visit);
	printf("\n");
}
Exemplo n.º 2
0
/********************************************************************
	Method:    ClearListtest
	Parameter:
	Returns:

	Purpose:   清空测试

*********************************************************************/
bool ClearListTest(LinkList &L)
{
    ClearList(L);
    TraverseList(L, visit);

    return true;
}
Exemplo n.º 3
0
/********************************************************************
	Method:    InsertTest
	Parameter:
	Returns:

	Purpose:   插入测试

*********************************************************************/
bool InsertTest(LinkList &L)
{
    ElemType e;
    e.data = 6;
    InsertElem(L, e, 4);	//	插入到最后一个位置

    e.data = 7;
    InsertElem(L, e, 1);	//	插入到第一个位置

    e.data = 8;
    InsertElem(L, e, 2);	//	插入到中间某一位置

    TraverseList(L, visit);

    /////////////////////////////////////////
    /*
    LinkList L1;
    CreateListByHead(L1, 0);

    e.data = 1;
    InsertElem(L1, e, 1);	//	在空链表中插入元素

    TraverseList(L1);
    */

    return true;
}
Exemplo n.º 4
0
/********************************************************************
	Method:    CreateListByTail
	Parameter:
	Returns:

	Purpose:   尾插法测试

*********************************************************************/
bool CreateListByTailTest(LinkList &L)
{
    CreateListByTail(L, 5);
    TraverseList(L, visit);

    return true;
}
Exemplo n.º 5
0
int main(){
printf("\nEnter the no of nodes you want to insert in LL: ");
int n;
scanf("%d",&n);
int i;
int data;
//LNode* head=NULL;
TNode* head=NULL;
for(i=0;i<n;i++){
printf("\nEnter data :  ");
scanf("%d",&data);
InsertList(&head,data);
}

printf("\nList created\n");
getch();
printf("\nPress enter to traverse list\n");
getch();
TraverseList(head);
getch();
printf("\nPress enter to create tree \n\n");
getch();
TNode* root=CreateTree_From_DLL(&head,n);
printf("\nTree created\n");
printf("\nPress enter to traverse tree inorder\n\n");
getch();
InOrder(root);
getch();

return 0;
}
Exemplo n.º 6
0
bool wxDebugContext::Dump(void)
{
#ifdef __WXDEBUG__
  {
    wxChar* appName = (wxChar*) wxT("application");
    wxString appNameStr;
    if (wxTheApp)
    {
        appNameStr = wxTheApp->GetAppName();
        appName = WXSTRINGCAST appNameStr;
        OutputDumpLine(wxT("----- Memory dump of %s at %s -----"), appName, WXSTRINGCAST wxNow() );
    }
    else
    {
      OutputDumpLine( wxT("----- Memory dump -----") );
    }
  }

  TraverseList ((PmSFV)&wxMemStruct::Dump, (checkPoint ? checkPoint->m_next : (wxMemStruct*)NULL));

  OutputDumpLine(wxEmptyString);
  OutputDumpLine(wxEmptyString);

  return true;
#else
  return false;
#endif
}
Exemplo n.º 7
0
/********************************************************************
	Method:    DeleteTest
	Parameter:
	Returns:

	Purpose:	删除元素测试

*********************************************************************/
bool DeleteTest(LinkList &L)
{
    DeleteElem(L, 6);	//	删除最后一个元素
    DeleteElem(L, 2);	//	删除中间元素
    DeleteElem(L, 1);	//	删除第一个元素

    TraverseList(L, visit);

    return true;
}
Exemplo n.º 8
0
/*
  Print out the list.
  */
bool wxDebugContext::PrintList (void)
{
#ifdef __WXDEBUG__
  TraverseList ((PmSFV)&wxMemStruct::PrintNode, (checkPoint ? checkPoint->m_next : (wxMemStruct*)NULL));

  return true;
#else
  return false;
#endif
}
Exemplo n.º 9
0
void NativeBindingGeneratorCore::Generate()
{
	BoolStack::Element inNativeBlockElement(mInNativeBlockStack, true);

	const size_t MAX_IDENTIFIER_DEPTH = 128;
	StringView identifiers[MAX_IDENTIFIER_DEPTH];
	const size_t numIdentifiers = SplitIdentifiers(mCollectionName, identifiers, MAX_IDENTIFIER_DEPTH);

	if (numIdentifiers > 0)
	{
		const StringView &collectionName = identifiers[numIdentifiers - 1];

		// Top of the .h file.
		const size_t BUFFER_SIZE = 1024;
		char includeGuard[BUFFER_SIZE];
		const char *n = mIncludeName;
		size_t i = 0;
		while ((*n != '\0') && (i < (BUFFER_SIZE - 1)))
		{
			const char c = *n++;
			includeGuard[i++] = char(isalnum(c) ? toupper(c) : '_');
		}
		includeGuard[i] = '\0';
		mHStream.Print("#ifndef %s\n#define %s\n\n#include \"bond/api/nativebinding.h\"\n\n", includeGuard, includeGuard);
		OpenNamespaces(mHStream, identifiers, numIdentifiers);
		mHStream.Print("extern const Bond::NativeBindingCollection ");
		collectionName.PrintTo(mHStream);
		mHStream.Print(";\n");
		CloseNamespaces(mHStream, numIdentifiers);
		mHStream.Print("\n");

		// Top of the .cpp file.
		mCppStream.Print("#include \"%s\"\n\n", mIncludeName);
		OpenNamespaces(mCppStream, identifiers, numIdentifiers);
		mCppStream.Print("\nconst Bond::NativeFunctionBinding ");
		collectionName.PrintTo(mCppStream);
		mCppStream.Print("_FUNCTIONS[] =\n{\n");

		// Spit out the function bindings.
		TraverseList(mTranslationUnitList);

		// Bottom of the .h file.
		mHStream.Print("\n#endif\n");

		// Bottom of the .cpp file.
		mCppStream.Print("\t{nullptr, nullptr}\n};\n\nconst Bond::NativeBindingCollection ");
		collectionName.PrintTo(mCppStream);
		mCppStream.Print(" =\n{\n\t");
		collectionName.PrintTo(mCppStream);
		mCppStream.Print("_FUNCTIONS,\n\t%" BOND_PRIu32 "\n};\n\n", mNumFunctions);
		CloseNamespaces(mCppStream, numIdentifiers);
	}
}
Exemplo n.º 10
0
void NativeBindingGeneratorCore::Visit(const EnumDeclaration *enumDeclaration)
{
	if (mInNativeBlockStack.GetTop())
	{
		NamespaceStack::Iterator it = mNamespaceStack.begin();
		PrintNamespaceStack(mHStream, it);

		mHStream.Print("enum %s\n{\n", enumDeclaration->GetName()->GetRawText());
		TraverseList(enumDeclaration->GetEnumeratorList());
		mHStream.Print("};\n");
	}
}
Exemplo n.º 11
0
/********************************************************************
	Method:    CreateListByHeadTest
	Parameter:
	Returns:

	Purpose:   头插法测试

*********************************************************************/
bool CreateListByHeadTest(LinkList &L)
{
    CreateListByHead(L, 3);	//	插入3个元素的链表
    TraverseList(L, visit);

    /*
    //	插入0个元素
    LinkList L1;
    CreateListByHead(L1, 0);
    TraverseList(L1);

    //	插入1个元素
    LinkList L2;
    CreateListByHead(L2, 1);
    TraverseList(L2);
    */

    return true;
}
Exemplo n.º 12
0
bool wxDebugContext::Dump(void)
{
  {
    const wxChar* appName = wxT("application");
    wxString appNameStr;
    if (wxTheApp)
    {
        appNameStr = wxTheApp->GetAppName();
        appName = appNameStr.c_str();
        OutputDumpLine(wxT("----- Memory dump of %s at %s -----"), appName, static_cast<const wxChar *>(wxNow().c_str()));
    }
    else
    {
      OutputDumpLine( wxT("----- Memory dump -----") );
    }
  }

  TraverseList ((PmSFV)&wxMemStruct::Dump, (checkPoint ? checkPoint->m_next : NULL));

  OutputDumpLine(wxEmptyString);
  OutputDumpLine(wxEmptyString);

  return true;
}
Exemplo n.º 13
0
PVOID
EnumerateModule32(
    PVOID ModuleList,
    PVOID Module
)
/*++

Routine Description:

    This routine returns a pointer to the next module in the list.

Arguments:

    ModuleList -- Supplies a pointer to the module list
    Module -- Supplies a pointer to the current module

Return Value:

    Pointer to the next module

--*/
{
    return TraverseList(ModuleList, Module);
}
Exemplo n.º 14
0
/*
  Print out the list.
  */
bool wxDebugContext::PrintList (void)
{
  TraverseList ((PmSFV)&wxMemStruct::PrintNode, (checkPoint ? checkPoint->m_next : NULL));

  return true;
}
Exemplo n.º 15
0
void MergeList2(SLinkList L)
{
	int na,nb;
	int i;
	int n;
	ElemType e;

	InitSpace(L);

	InitList(L,na);
	InitList(L,nb);

	printf("请输入A中数据的个数:");
	scanf("%d",&i);
	if(i>0)
		n=i;

	for(i=0;i<n;i++)
	{
loop1:
		scanf("%d",&e);
		if(!LocateElem(L,na,e,compare))
			ListInsert(L,na,i+1,e);
		else
		{
			printf("已存在,请重新输入:");
			goto loop1;
		}
	}
	printf("遍历链表");
	TraverseList(L,na,visit);
	printf("\n");

	printf("请输入B中数据的个数:");
	scanf("%d",&i);
	if(i>0)
		n=i;

	for(i=0;i<n;i++)
	{
loop2:
		scanf("%d",&e);
		if(!LocateElem(L,nb,e,compare))
			ListInsert(L,nb,i+1,e);
		else
		{
			printf("已存在,请重新输入:");
			goto loop2;
		}
	}
	printf("遍历链表");
	TraverseList(L,nb,visit);
	printf("\n");

	for(int j=0;j<ListLength(L,nb);j++)
	{
		if(GetElem(L,nb,j+1,e))
		{
			if(!(i=LocateElem(L,na,e,compare)))
			{
				i=ListLength(L,na);
				ListInsert(L,na,++i,e);
			}
			else
				ListDelete(L,na,i,e);
		}
	}

	printf("遍历链表");
	TraverseList(L,na,visit);
	printf("\n");
}
Exemplo n.º 16
0
//expand
void test2()
{
	SLinkList L;
	SLinkList Lk;
	ElemType e;
	int i=0;
	int N=10;
	int n;

	InitSpace(L);
	InitList(L,n);
	
	printf("表是否为空(1:非空,0:空),结果:%d\n",!ListEmpty(L,n));
	printf("表长%d\n",ListLength(L,n));
	
	for(i=1;i<=5;i++)
	{
		ListInsert(L,n,i,2*i);
	}
	
	printf("插入5个元素(2,4,6,8,10),结果:");
	TraverseList(L,n,visit);
	printf("\n");
	
	i=3;
	if(PriorElem(L,n,3,e))
		printf("%d的前驱为%d\n",i,e);
	if(NextElem(L,n,3,e))
		printf("%d的后继为%d\n",i,e);
	
	for(i=1;i<=5;i++)
	{
		ListInsert(L,n,2*i-1,2*i-1);
	}
	
	printf("插入5个元素(1,3,5,7,9)后结果:");
	TraverseList(L,n,visit);
	printf("\n");
	
	printf("表是否为空(1:非空,0:空),结果:%d\n",!ListEmpty(L,n));
	printf("表长%d\n",ListLength(L,n));
	
	for(i=9;i<=10;i++)
	{
		printf("删除%d个元素为",i);
		if(ListDelete(L,n,i,e))
			printf("%d\n",e);
		else
			printf("删除失败\n");
	}
	
	int j=0;
	for(i=-1;i<=1;i++)
	{
		printf("查找%d所在位置",i);
		j=LocateElem(L,n,i,compare);
		if(j)
			printf("%d\n",j);
		else
			printf("查找失败\n");
	}

		
	for(i=-1;i<=N+5;i+=3)
	{
		if(PriorElem(L,n,i,j))
			printf("查找到%d的前驱%d\n",i,j);
		else
			printf("查找%d的前驱失败\n",i);

		if(NextElem(L,n,i,j))
			printf("查找到%d的后继%d\n",i,j);
		else
			printf("查找%d的后继失败\n",i);

	}

	j=ClearList(L,n);
	if(j)
		printf("清空链表成功");
	else
		printf("清空失败");
	
	printf("表是否为空(1:非空,0:空),结果:%d\n",!ListEmpty(L,n));
	printf("表长%d\n",ListLength(L,n));

	MergeList2(Lk);
	printf("\n");
}