데이터 구조 - 단일 링크 찾기 번호 로 찾기

843 단어 데이터 구조
#include
#include
#define ERROR -40000
using namespace std;

typedef struct LNODE
{
	int data;
	struct LNODE *next;
}Lnode;

Lnode *Input(int n)
{
	Lnode *head,*p,*q;
	head=p=(Lnode*)malloc(sizeof(Lnode));
	p->next=NULL;
	for(int i=0;i>data;
		q=(Lnode*)malloc(sizeof(Lnode));
		q->data=data;
		q->next=p->next;
		p->next=q;
		p=q;
	}
	return head;
}

int FindData(Lnode *L,int id)
{
	Lnode *p;
	p=L->next;
	int j=1;
	while(p!=NULL&&jnext;
		j++;
	}
	if(j!=id||p==NULL) return ERROR;//        n+1     bug,         
	else return p->data;
}

int main()
{
	int n;
	while(cin>>n)
	{
		Lnode *p=Input(n);
		cout<>num;
			int find_data=FindData(p,num);
			if(find_data!=ERROR)
			{
				cout<

좋은 웹페이지 즐겨찾기