#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
int seatnumber;
char name[ 20 ] ;
} PASSENGER;
struct node
{
int seatnumber;
char name[ 20 ] ;
struct node * link;
} ;
typedef struct node* NODE;
NODE getnode( )
{
NODE x;
x
= ( NODE
) malloc ( sizeof ( struct node
) ) ; if ( x== NULL)
{
}
return x;
}
NODE AddPassenger( PASSENGER item, NODE first)
{
NODE temp;
temp= getnode( ) ;
temp-> seatnumber= item.seatnumber ;
temp-> link= NULL;
if ( first== NULL)
return temp;
temp-> link= first;
return temp;
}
NODE AddPassenger_last( PASSENGER item, NODE first)
{
NODE temp, cur;
temp= getnode( ) ;
temp-> seatnumber= item.seatnumber ;
temp-> link= NULL;
if ( first== NULL)
return temp;
cur= first;
while ( cur-> link!= NULL)
{
cur= cur-> link;
}
cur-> link= temp;
return first;
}
NODE DeletePassenger( NODE first)
{
NODE temp;
if ( first== NULL)
{
printf ( "passenger list is empty\n " ) ; return NULL;
}
temp= first;
temp= temp-> link;
printf ( "delete passenger record :seatnumber=%d\n " , first
-> seatnumber
) ; return temp;
}
NODE DeletePassenger_last( NODE first)
{
NODE cur, prev;
if ( first== NULL)
{
printf ( "passenger list is empty cannot delete\n " ) ; return first;
}
if ( first-> link== NULL)
{
printf ( "delete passenger record:seatnumber=%d\n " , first
-> seatnumber
) ; return NULL;
}
prev= NULL;
cur= first;
while ( cur-> link!= NULL)
{
prev= cur;
cur= cur-> link;
}
printf ( "delete passenger record:seatnumber=%d\n " , cur
-> seatnumber
) ; prev-> link= NULL;
return first;
}
void display( NODE first)
{
NODE cur;
int count= 0 ;
if ( first== NULL)
{
printf ( "passenger list is empty\n " ) ; return ;
}
cur= first;
while ( cur!= NULL)
{
printf ( "%d\t %s\t \n " , cur
-> seatnumber
, cur
-> name
) ; cur= cur-> link;
count++;
}
printf ( "number of passengers=%d\n " , count
) ; }
void main( )
{
NODE first;
int choice;
PASSENGER item;
first= NULL;
for ( ;; )
{
printf ( "1.Add passengers from first\n 2.Add the passenger from last \n 3.Delete the passengers from first \n 4.Delete the passenger from last \n 5.display the passengers\n 6.exit\n " ) ; switch ( choice)
{
case 1 :
scanf ( "%d" ,& item.
seatnumber ) ; first= AddPassenger( item, first) ;
break ;
case 2 :
scanf ( "%d" ,& item.
seatnumber ) ; first= AddPassenger_last( item, first) ;
break ;
case 3 :
first= DeletePassenger( first) ;
break ;
case 4 :
first= DeletePassenger_last( first) ;
break ;
case 5 :
display( first) ;
break ;
default :
}
}
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+CiNpbmNsdWRlPHN0cmluZy5oPgoKdHlwZWRlZiBzdHJ1Y3QKewppbnQgc2VhdG51bWJlcjsKY2hhciBuYW1lWzIwXTsKfVBBU1NFTkdFUjsKCnN0cnVjdCBub2RlCnsKaW50IHNlYXRudW1iZXI7CmNoYXIgbmFtZVsyMF07CnN0cnVjdCBub2RlICpsaW5rOwp9OwoKdHlwZWRlZiBzdHJ1Y3Qgbm9kZSpOT0RFOwpOT0RFIGdldG5vZGUoKQp7Ck5PREUgeDsKeD0oTk9ERSltYWxsb2Moc2l6ZW9mKHN0cnVjdCBub2RlKSk7CmlmKHg9PU5VTEwpCnsKcHJpbnRmKCJvdXQgb2YgbWVtb3J5XG4iKTsKZXhpdCgwKTsKfQpyZXR1cm4geDsKfQoKTk9ERSBBZGRQYXNzZW5nZXIoUEFTU0VOR0VSIGl0ZW0sTk9ERSBmaXJzdCkKewpOT0RFIHRlbXA7CnRlbXA9Z2V0bm9kZSgpOwp0ZW1wLT5zZWF0bnVtYmVyPWl0ZW0uc2VhdG51bWJlcjsKc3RyY3B5KHRlbXAtPm5hbWUsaXRlbS5uYW1lKTsKdGVtcC0+bGluaz1OVUxMOwppZihmaXJzdD09TlVMTCkKcmV0dXJuIHRlbXA7CnRlbXAtPmxpbms9Zmlyc3Q7CnJldHVybiB0ZW1wOwp9CgpOT0RFIEFkZFBhc3Nlbmdlcl9sYXN0KFBBU1NFTkdF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