7-9 链表操作(10 分)

#include<iostream>
#include<queue>
using namespace std;
int main(){
queue<int>q;
int n;
while(cin>>n,n!=-1){
	if(n%2!=0)
	q.push(n);
}
cout<<q.front();q.pop();
while(!q.empty()){
	cout<<" "<<q.front();q.pop();
}	

	return 0;
}

7-9 链表操作(10 分)

编程实现:输入若干个正整数(输入-1为结束标志),建立一个单向链表,将其中的偶数值结点删除后输出。链表节点定义为: struct Node{ int data; struct Node *next; }

输入输出示例:括号内为说明

输入样例:

1 2 3 4 5 6 7 -1

输出样例:

1 3 5 7

猜你喜欢

转载自blog.csdn.net/qq_39427510/article/details/80199674