链接列表字符串排序问题

时间:2018-04-04 04:37:54

标签: c++ string sorting linked-list

问题是如果我输入1,然后输入2和123.它将排序1,123,2 我如何使它排序1,2,123

项目是已创建的记录。 跑步者是横越者。

 public class MyFireBaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onCreate() {
        super.onCreate();
    }

    /**
     * Called when message is received.
     *
     * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
     */
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.e("Notification", "From : " + remoteMessage.getFrom());
        Log.e("Notification", "Data : " + remoteMessage.getData().toString());
        String type = remoteMessage.getData().get("notificationType");
        try {
            sendNotification(remoteMessage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Create and show a simple notification containing the received FCM message.
     */
    private void sendNotification(RemoteMessage remoteMessage) throws UnsupportedEncodingException {
        String title, message;
        title = getString(R.string.app_name);
        message = "" + remoteMessage.getData().get("text"); //instead of text you can have your key getting received in notification

       // Pending intent will perform redirection on clicking Notification

        Intent intent = new Intent(this, MainActivity.class);
        intent.putExtra("fromNotification", true);
        PendingIntent contentIntent = PendingIntent.getActivity(this,
                (int) System.currentTimeMillis(), intent,
                PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT
                        | PendingIntent.FLAG_CANCEL_CURRENT);


        // Let's create notification to be displayed


        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
        NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();
        notiStyle.setSummaryText(message);
        Bitmap remotePicture = null;     // This will be used only when you will have image url in notification and want to display image as a notification.

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // incase you want to set your custom sound for notification

        notificationBuilder
                .setSmallIcon(R.drawable.ic_notification_icon)
                .setContentTitle(title)
                .setContentText(message)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setColor(ContextCompat.getColor(getApplicationContext(), R.color.app_purple))
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(contentIntent);

     // If there is an image URL to be displayed, get the bitmap from URL and pass it to notification builder

          if (remoteMessage.getData().containsKey("image")) {  
                try {
                    remotePicture = BitmapFactory.decodeStream((InputStream) new URL(remoteMessage.getData().get("image")).getContent());
                    notiStyle.bigPicture(remotePicture);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (remotePicture != null) notificationBuilder.setStyle(notiStyle);
            }

            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

      // If you are using device with OS OREO or ABOVE

       if (VERSION.SDK_INT >= VERSION_CODES.O) {
            String channelId = "your_app_notificaiton_channel_id";
            CharSequence channelName = "Your App Channel";
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance);
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(Color.RED);
            notificationChannel.enableVibration(true);
            notificationChannel.setShowBadge(true);

            AudioAttributes audioAttributes = new AudioAttributes.Builder()
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
                    .build();

            notificationChannel.setSound(soundUri, audioAttributes);
            notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
            assert mNotificationManager != null;
            notificationManager .createNotificationChannel(notificationChannel);
            notificationBuilder.setChannelId(channelId);
        }

        notificationManager.notify((int) System.currentTimeMillis() /* ID of notification */, notificationBuilder.build());
    }
}

1 个答案:

答案 0 :(得分:1)

您可以使用std::stoi来比较整数而不是字符串:

std::stoi(Item->ID) < std::stoi(Runner->Next->ID)

您实际上可能希望将ID存储为整数,而不是字符串。

如果您的ID可以是“123AB”,那么您可以使用以下内容提取数字:

string str = "123AB";
size_t last_index = str.find_last_of("0123456789");
string result = str.substr(0, last_index + 1); // result = "123";