链表

#include
#include
typedef struct Node {
          int num;
          struct Node * next;
}Node;
int main(){
//==================build LinkedList============
        printf ("%d\n",sizeof(Node));
        int  len=10;
        Node  *head, *temp, *tail;
        for(int i=0; i num =i;
        if( i==0){
        head=n;
        temp=head;
}
     else{
               temp->next=n;
               temp=n;
      }
}
          tail=temp;
          temp->next=NULL;
//==================append Node LinkedList============
Node *newNode = malloc (sizeof(Node));
          newNode->num=20;
          tail->next =newNode;
          newNode->next=NULL;
          tail  = newNode;
          temp=newNode;

//=================remove  Node from LinkedList==========

          temp=head;
          int index=0;
          Node *t;
          if( index > 0){
          for( int i = 0; i < index-1; ++i){
                temp=temp->next ;
  }
          t=temp->next;
          temp->next =temp->next ->next;
            free(t);
  }
          else if(index==0){
          t=head;
          head = head -> next ;
          free(t);
    }
        temp=head;
        while( temp!=NULL){
                printf("%d\t%p\n",temp->num ,temp);
                    temp=temp->next;
      }
          return 0;
}

你可能感兴趣的:(链表)