2012.1.3 链表

typedef struct node
{
 int data1;
 char data2[10];
 node *next;
}*ptrN;

ptrN accessNode(const ptrN head,int n)
{
 ptrN tmpNode;
 if (head == 0)
 {
  return 0;
 }
 else
 {
  tmpNode = head;
 }
 for (int i = 0;i < n-1; i++)
 {
  if (tmpNode->next == 0)
  {
   return 0;
  }
  tmpNode = tmpNode->next;
 }
 return tmpNode;
}

ptrN accessTrail(const ptrN head)
{
 ptrN tmpNode;
 if (head == 0)
 {
  return 0;
 }
 else
 {
  tmpNode = head;
 }
 while (tmpNode->next)
 {
  tmpNode = tmpNode->next;
 }
 return tmpNode;
}

 

 

tmpNode->data = 10;

或者(*tmpNode).data = 10;

 

 

 

 

 

 

 

posted @ 2012-01-03 22:26  rookieeeeee  阅读(87)  评论(0编辑  收藏  举报